日期:2014-05-20  浏览次数:20593 次

datalist中有一个checkbox和label 如何 选中checkbox时 获得datalist的label的值呀
同上

------解决方案--------------------
datalist.Items[i].FondControl( "lableId ")
------解决方案--------------------
绑定datalist时给checkbox加一个click事件,
e.Item.FondControl( "checkBoxID ").Attributes.Add( "onclick ", "doSomeThing( ' "+e.Item.FondControl( "lableId ").ClientID+ " ' ");
------解决方案--------------------
呵呵,写得有点问题罢了,我修改一下,测试成功了,记得及时结帐啊:
<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+ " '); ");
}

------解决方案--------------------
for (int i = 0; i < DataList1.Items.Count; i++)
{
CheckBox chk1 = (CheckBox)DataList1.Items[i].FindControl( "CheckBox1 ");
if (chk1.Checked)
{
Label lb = (Label)DataList1.Items[i].FindControl( "Label1 ");
}
}
Response.Write(lb.Text);


给分 给分