checkbox是否被选中问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 14:51:17
System.Web.UI.WebControls.CheckBox CheckBox1;
for (int i = 0, j = DataList1.Items.Count; i < j; i++)
{
CheckBox cbx = (CheckBox)DataList1.Items[i].FindControl("CheckBox1");
if (cbx.Checked == true)
{
int id = i + 1;
string strSql = string.Empty;
strSql = "update Url set flag='1' where id='" + id + "'";
try
{
DbHelper.Query(strSql, "Url");

}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
else
{
int id = i + 1;
string strSql =

前台的CheckBox的ID为:CheckBox1,runat='server',为什么不能找到?

LZ不如Debug一下,断点设置在
CheckBox cbx = (CheckBox)DataList1.Items[i].FindControl("CheckBox1");
看看cbx是否为null。再做判断