如题,还有就是怎么为checkBox付值

解决方案 »

  1.   

    foreach(GridViewRow row in GridView1.Rows) {
    CheckBox chk = row.FindControl("MyCehckBoxID") as CheckBox;
    if(chk.Checked) { 选中
        object key = GridView1.DataKeys[row.RowIndex].Value;
        // ...
    }
    }
      

  2.   

    function IsSelect()
        {
             var objtb=window.document.getElementById('GVRc');
            //计算数据列行数        var rownum=objtb.rows.length;
            for(var i=1;i<rownum;i++)
            {
                checkbox=objtb.rows[i].cells[0].children[0];
                if(checkbox.type="checkbox")
                {
                    if(checkbox.checked==true)
                    {
                        if(window.confirm('确定删除吗?')==1)
                        {
                          
                             return true ;
                         }
                         else
                         {
                            window.event.returnValue=false;
                            return false;
                         }
                    }
                }
            }
            window.alert('请选择要删除的记录!');
           window.event.returnValue=false;
        }
      

  3.   

    还有就是怎么为checkBox付值=========MyCheckBox.Checked = true; // false;
      

  4.   

    string idStr 
    foreach (GridViewRow row in gvYgList.Rows)
            {
          CheckBox QyCheck = (CheckBox)row.FindControl("CheckBox1");//楼主,主要是这句话
                if (QyCheck != null)
                {
                    if (QyCheck.Checked == true)
                    {
                      idStr += gvYgList.DataKeys[row.RowIndex].Value.ToString() + ",";
                     }
                }
            }
      

  5.   

    GridView 实现服务器端和客户端全选的两种方法http://dotnet.aspx.cc/article/a8efc285-f0b1-4f8f-8e73-2b7d8724a47c/read.aspx
      

  6.   

    用个循环遍历
    for(int i = 0;i < GridView1.Rows.Count;i++)
    {
    check = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
    if(check!=null)
    {
    if(check)
    {
    //获取被选中的列
    }
    }
    }
      

  7.   

    foreach (GridViewRow rw in GridView1.Rows)CheckBox ch = ((CheckBox)rw.Cells[i].FindControl("CheckBox1"));if (true == ch.Checked)
      

  8.   

    思路就是你自己写一个方法
    遍历你的DataGridView的所有行,返回选中的行数。

        private int GetCheckBoxNum()
        {
            int checkNum = 0;
            int editIndex = 0;
            for (int i = 0; i < Dg1.Items.Count; i++)
            {
                CheckBox chk = (CheckBox)Dg1.Items[i].Cells[0].Controls[1];
                if (chk.Checked)
                {
                    checkNum = checkNum + 1;
                    editIndex = i;
                }
            }
            if (checkNum == 1)
            {
                return checkNum;
            }
            else if (checkNum == 0)
            {
                return -1;
            }
            else
            {
                return checkNum;
            }
        }
      

  9.   

    CheckBox chk;
            foreach (GridViewRow r in GridView1.Rows)
            {
                chk = (CheckBox)r.FindControl("CheckBox2");
                if (chk != null)
                {
                    if (chk.Checked)
                    {
                         //用GridView1.DataKeys[r.RowIndex].Value.ToString()找到主键列的值,然后进行更新操作
                    }
                }
            }        BindGrid();//重新绑定数据