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;//获取名称
}
}
}
<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;//获取名称
}
}
}
相关文章推荐
- IOS 项目里面必要配置button 不能同时触发点击事件
- Android基础:listview的item点击事件会使里面的Button也出现按压的效果
- 想实现在ListFragment里面的ListView的item里面的Button的点击事件
- android中ListView点击和ListView的item里面的button或ImageView不能同时生效的解决
- 关于Unity中NGUI的Checkbox复选框、Slider滑动条和Button的6种触发回调事件的方式
- ulua和CS之间配合对UIScrollView里面的Button绑定事件
- 一步一步地实现菜单栏(JMenuBar)工具栏(JPopupMenu)组合框(JComboBox)复选框(JCheckBox)单选按钮(JRadioButton)文本域的综合应用(一)
- Button、DropDownList、CheckBox等常用事件
- listview的子布局如果有HorizontalScrollView、CheckBox 、button,可能会导致onListItemClick点击事件失效。
- 安卓开发学习之014 Button应用详解(样式、背景、按钮单击、长按、双击、多击事件)
- 无法datalist里面的CheckBox控件选中状态
- java图像界面开发简单实例-JRadioButton、JCheckBox、JLabel的应用
- js触发asp.net的Button的Onclick事件应用
- 解决android listview中OnItemClickListener事件和里面button点击事件冲突问题
- Android编程基础之简单Button事件响应综合提示控件Toast应用示例
- datagrid里面的ImageButton 重复触发delete事件
- HTML 事件解说之二 Button Link CheckBox Select
- Android 同时监听多个Button事件
- 讨论: 在WebControl中的Button,同时有onClientClick和onclick事件,验证控件实效
- Android基础教程之Button事件触发AlertDialog简单小窗口的应用