DataGrid如何实现checkbox控件的判断?就是判断每行的checkbox控件是否被checked了,请问如何做?

解决方案 »

  1.   

    foreach(DataGridItem item in this.iwgrid.Items)
    {
    CheckBox check = (CheckBox)item.FindControl("CheckBoxName");
    if(check.Checked)
    {
     .....
      

  2.   

    把分拿过来
    http://community.csdn.net/Expert/topic/4271/4271124.xml?temp=.9170191
      

  3.   

    oasis_wen(十有八九)的方法正确,是我弄错了,不好意思。还有一个问题:
    我想在页面下面放一个按钮,点击这个按钮,判断datagrid中所有checkbox被选中的行进行处理,请问我该如何做,原先写的代码
    private void Button2_Click(object sender, System.EventArgs e)
    {
    string ID="";
    string birthdaynotice="";
    int num=0-int.Parse(TextBox1.Text);
    foreach(DataGridItem item in dgInferEngineInfo.Items)
    {
    CheckBox check = (CheckBox)item.FindControl("cb");
    if(check.Checked)
    {
    ID=item.Cells[0].Text;
    birthdaynotice=DateTime.Parse(item.Cells[1].Text).AddDays(num).ToShortDateString();
    string strSql = "update clubmember set " + 
    "birthdaynotice='"+birthdaynotice+
    "' where ID="+ID;
                               ExecuteSql(strSql); LoadGrid();
    }
    }
    }结果运行的时候出现错误集合已修改;枚举操作可能不会执行!!!
      

  4.   

    会不会是因为重新load了grid?
      

  5.   

    不要用foreach,用for( int index = 0; index < dgInferEngineInfo.Items.Count; ++ index )
    {
       DataGridItem item = dgInferEngineInfo.Items[index];   ...
    };foreach得到的枚举是只读的。枚举过程中不允许操作集合