protected void btnTest_Click(object sender, EventArgs e)
{
int intTest = 0;
for (int j = 0; j < gvTest.Rows.Count; j++)
{
CheckBox CB = (CheckBox)gvTest.Rows[j].FindControl("cbTest");
if (CB.Checked)
{
intTest = intTest + 1;
CB.Checked = true;
}
}
}
上面cbTest是GridView中定义的CheckBox,gvTest是cbTest所在的GridView,可是不管cbTest有没有勾选,CB.Checked一直都是false,不知道是什么原因,我上网查了,好多地方都说GridView中操作CheckBox就是这样的呀,那位高手帮我看看啊,谢谢!!!
{
int intTest = 0;
for (int j = 0; j < gvTest.Rows.Count; j++)
{
CheckBox CB = (CheckBox)gvTest.Rows[j].FindControl("cbTest");
if (CB.Checked)
{
intTest = intTest + 1;
CB.Checked = true;
}
}
}
上面cbTest是GridView中定义的CheckBox,gvTest是cbTest所在的GridView,可是不管cbTest有没有勾选,CB.Checked一直都是false,不知道是什么原因,我上网查了,好多地方都说GridView中操作CheckBox就是这样的呀,那位高手帮我看看啊,谢谢!!!
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i <=GridView1.Rows.Count - 1;i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (CheckBox2.Checked)
{
cbox.Checked = true;
}
else
cbox.Checked = false;
}
}
這裡能不能找到cbTest?
debug看看
是可以找到cbTest的,只是CB.Checked永远都是false
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Myconn"].ConnectionString);
SqlCommand com;
for(int i=0;i<=GridView1.Rows.Count-1;i++)
{
CheckBox cbox=(CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if(cbox.Checked)
{
string sql="update yuangong set 在职情况ID='"+this.DropDownList2.SelectedValue+"'"+"where 职工号='"+GridView1.DataKeys[i].Value+"'";
com=new SqlCommand(sql,conn);
conn.Open();
com.ExecuteNonQuery();
conn.Close();
}
}
setbind(Convert.ToInt32(this.DropDownList1.SelectedValue));
}
选中之后
我一直这样做没发现有什么问题~~~
这样你后面无论怎样,所有CheckBox的Checked都是false
protected void btnTest_Click(object sender, EventArgs e)
{
int intTest = 0;
for (int j = 0; j < gvTest.Rows.Count; j++)
{
CheckBox CB = (CheckBox)gvTest.Rows[j].FindControl("cbTest");
if (CB.Checked == true)
{
intTest = intTest + 1;
CB.Checked = true;
}
}
}