|
发表于 2020-3-18 22:45:01
|
显示全部楼层
呵呵,写得有点问题罢了,我修改一下,测试成功了,记得及时结帐啊:
<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>
下面是后台代码:
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+"');");
}
|
|