目前datagridview首列是复选框,我想根据选中的时候删除数据,怎么实现,
 是否被选中复选框就行

解决方案 »

  1.   

    可以添加个button 
     我用伪语言给你写一哈哈
     你之前的sql-db 连接语句和 sqlcommand的设置我就不写了哈。
       在button里添加如下代码:
       if(checkbox.checked==true)
         { 
             string strsql=checkbox.text.tostring();
             ..... (执行sql语句)    
         }  希望对你有用!!
       
      

  2.   

      for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                              
                        int id = (int)this.dataGridView1.Rows[i].Cells["num"].Value;
                        int val = AssertManager.DelAssert(id);
                        if (val > 0)
                        {                    }
                        else
                        {
                            MessageBox.Show("no");
                        }                }怎样循环复选框,给代码看看,谢谢大家
      

  3.   

    循环复选框? 服务器控件直接取值就行了啊。要是HTML控件
    function setCheck(obj) 
        {         
            var comxid=obj;            
            if(document.getElementById(comxid).checked==true) 
            {     
                    document.getElementById("check_ids").value = document.getElementById("check_ids").value+obj+",";                
            } 
            else 
            { 
                    document.getElementById("check_ids").value = document.getElementById("check_ids").value.replace(obj+",",'');                 
            } 
        }    <input type="checkbox" style="width:20px;height:20px;" id="ads" name="ads" value='阿萨德'  onclick="setCheck(this.value);"/>
            <input type="hidden" id="check_ids" name="check_ids"/>
    String value= Request.Form["check_ids"].TrimEnd(',');
      

  4.   

    http://blog.csdn.net/zhou__zhou/archive/2006/12/27/1464392.aspx
    http://blog.csdn.net/wyaspnet/archive/2008/10/10/3049901.aspx
      

  5.   

    倒。写错了 
    function setCheck(obj,value) 
        {         
            var comxid=obj;            
            if(document.getElementById(comxid).checked==true) 
            {     
                    document.getElementById("check_ids").value = document.getElementById("check_ids").value+value+",";                
            } 
            else 
            { 
                    document.getElementById("check_ids").value = document.getElementById("check_ids").value.replace(value+",",'');                 
            } 
        }    
    <input type="checkbox" style="width:20px;height:20px;" id="ads" name="ads" value='阿萨德'  onclick="setCheck(this.name,this.value);"/>
            <input type="hidden" id="check_ids" name="check_ids"/>
      

  6.   

     foreach (GridViewRow gvr in Gridno.Rows)
                {
                    CheckBox cb = (CheckBox)Gridno.Rows[gvr.RowIndex].FindControl("CkItemno");//chItemno 是复选框的Id
                    if (cb.Checked)
                    {
                        if (TempPersonId.Trim() == "")
                            TempPersonId = Gridno.DataKeys[gvr.RowIndex].Value.ToString();
                        else
                        {
                            TempPersonId += "','" + Gridno.DataKeys[gvr.RowIndex].Value.ToString();
                        }
                    }
                }