|
Hehe, I wrote a bit wrong, I modified it, the test was successful, remember to check out in time:
<asp: DataList id = "DataList1" runat = "server" OnItemDataBound = "init">
<ItemTemplate>
<asp: CheckBox ID = t1 Runat = server />
<asp: Label ID = l1 Runat = server>
<% # DataBinder.Eval (Container.DataItem, "b")%> </ asp: Label>
</ ItemTemplate>
</ asp: DataList>
<script language = javascript>
function doSomeThing (objName) {
alert (document.getElementById (objName) .innerHTML);
};
</ script>
Here is the background code:
public void init (object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
CheckBox cb1 = (CheckBox) (e.Item.FindControl ("t1"));
Label lb = (Label) (e.Item.FindControl ("l1"));
cb1.Attributes.Add ("onclick", "doSomeThing ('" + lb.ClientID + "');");
} |
|