您的位置:首页 > 其它

datalist button事件,button不在datalist里面,CheckBox 同时应用

2010-04-01 10:00 344 查看
<asp:DataList ID="datalistClients" runat="server" Width="100%" DataKeyField="ClientsID">
<ItemTemplate>
<table width="100%" style="font-size: 12px" border="0" align="center" cellpadding="0"
cellspacing="1" bgcolor="#c0de98" onmouseover="changeto()" onmouseout="changeback()">
<tr>
<td height="20" bgcolor="#FFFFFF" style="text-align: center; width: 5%">

<asp:CheckBox ID="xuanze" runat="server" />
</td>

<td height="20" bgcolor="#FFFFFF" style="text-align: center; width: 15%">
<%# Eval("CompanyName")%>
</td>
<td bgcolor="#FFFFFF" height="20" style="text-align: center; width: 20%">
<asp:Label ID="Label3" runat="server" Text='<%# Eval("ClientsName")%>'> </asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

<asp:Button ID="Button2" runat="server" Text="确 定" onclick="Button2_Click" />

在button事件中获取CheckBox 点击的id 同时获取去id对应的名称

protected void Button2_Click(object sender, EventArgs e)
{
foreach (DataListItem dr in datalistClients.Items)//对datalist中的每一行进行判断
{
CheckBox CB = (CheckBox)dr.FindControl("xuanze");
if (CB.Checked)
{
int ID = int.Parse(datalistClients.DataKeys[dr.ItemIndex].ToString());//获取id
string name = ((Label)dr.FindControl("Label3")).Text;//获取名称
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐