asp.net Repeater取得CheckBox选中的某行某个值的c#写法
作者:
asp.net(c#)利用Repeater取得CheckBox选中行的某个值的代码
1、
foreach (Control c in this.rptTables.Controls)
{
CheckBox cbx = (CheckBox)c.FindControl("cbxId");
TextBox tbx = (TextBox)c.FindControl("tbxTableName");
if (cbx != null)
{
if (cbx.Checked == true)
{
common.salert(tbx.Text);
}
}
}
2、
for (int i = 0; i < this.rptTables.Items.Count; i++)
{
CheckBox cbx = (CheckBox)rptTables.Items[i].FindControl("cbxId");
TextBox tbx = (TextBox)rptTables.Items[i].FindControl("tbxTableName");
if (cbx != null)
{
if (cbx.Checked)
{
common.salert(tbx.Text);
}
}
}
关键点:在每行再写个隐藏的控件我是用TextBox,代码如下:
<asp:TextBox id="tbxTableName" runat="server" Text='<%#Eval("TABLE_NAME") %>' style="display:none;" />
foreach (Control c in this.rptTables.Controls)
{
CheckBox cbx = (CheckBox)c.FindControl("cbxId");
TextBox tbx = (TextBox)c.FindControl("tbxTableName");
if (cbx != null)
{
if (cbx.Checked == true)
{
common.salert(tbx.Text);
}
}
}
2、
for (int i = 0; i < this.rptTables.Items.Count; i++)
{
CheckBox cbx = (CheckBox)rptTables.Items[i].FindControl("cbxId");
TextBox tbx = (TextBox)rptTables.Items[i].FindControl("tbxTableName");
if (cbx != null)
{
if (cbx.Checked)
{
common.salert(tbx.Text);
}
}
}
关键点:在每行再写个隐藏的控件我是用TextBox,代码如下:
<asp:TextBox id="tbxTableName" runat="server" Text='<%#Eval("TABLE_NAME") %>' style="display:none;" />