如何取出数据控件Repeater中CheckBox
protected void Button4_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
CheckBox ChkBox = (CheckBox)item.FindControl("ChkBox");
if (ChkBox.Checked)
{
int[] show;
for (int i = 0; i >= Convert.ToInt32(ChkBox.Checked); i++)
{
int show = Convert.ToInt32(ChkBox.ToolTip);
string sql = "select * from Record where id = '" + show + "'";
}
}
}
}
后台的代码
<asp:CheckBox Checked="false" ID="ChkBox" runat="server" ToolTip='<%# DataBinder.Eva(Container.DataItem, "id")%>' />
前台代码
Button4是取出Repeater中CheckBox的ID值现在我已经能取出来了!但是只能取出一个ID值想用循环写不知道怎么写就是上边红色的部分请高手帮忙!!
------解决方案--------------------
C# code
protected void Button4_Click(object sender, EventArgs e)
{
string sql="select * from Record where id = -1 ";//初始化,不选择任何记录
foreach (RepeaterItem item in Repeater1.Items)
{
CheckBox ChkBox = (CheckBox)item.FindControl("ChkBox");
if (ChkBox.Checked)
{
int id = Convert.ToInt32(ChkBox.ToolTip);
sql+= " or id="+id;
}
}
}