假设CheckBox在第0列:
chk = (CheckBox)oDataGridItem.Cells[0].FindControl("chk");

解决方案 »

  1.   

    这是我写的删除 每一行开头有个CheckBox 
           #region 删除
            protected void lbDel_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < gvArticleList.Rows.Count; i++)
                {
                    CheckBox cbSel = (CheckBox)gvArticleList.Rows[i].FindControl("cbTitle");
                    if (cbSel.Checked)
                    {
                        string strId = gvArticleList.DataKeys[i].Value.ToString().Trim();//删除数据                    
    ...
                        }
            #endregion
      

  2.   

    DataGrid只能选中一个的(selectedindex)。所以选择多个的话,不能用设置selectedindex的方法,只能遍历DataGrid判断CheckBox是否选中
      

  3.   

    private void kindBtn_Click(object sender, System.EventArgs e)
    {
    KindsInfoDB kindsinfo=new KindsInfoDB();
    //CheckBox chk;
    for (int i = 0; i < myDataGrid.Items.Count; i++)
    {
    CheckBox chk = (CheckBox)myDataGrid.Items[i].FindControl("chk");
    if (chk.Checked)
        
    {
    try
    {
     kindsinfo.updateindetailkinds(API.getInt32(catalogueList.SelectedValue),API.getInt32(kindsList.SelectedValue));
    }
    catch(Exception ex)
    {
    string sRawURL = Request.RawUrl; if(sRawURL.IndexOf("?") > -1)
    {
    sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
    }

    Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl=" + sRawURL + "&ErrorMessage=" + Server.UrlEncode(ex.Message.Replace("\n"," ")));
    }
    }
    Response.Write("<script>alert(\"归类完毕!\");</script>"); }
    }
    不能实现,dataGri控件还是会遍历所有行,然后更新了
      

  4.   

    在每行上查找
    你现在是在datagrid上查找
      

  5.   

    我在datagrid上查找 checkbox有没被选中的,不对?
      

  6.   

    private void kindBtn_Click(object sender, System.EventArgs e)//归类操作
    {
       KindsInfoDB kindsinfo=new KindsInfoDB();
    CheckBox chk;
    int nID=0;
    foreach(DataGridItem oDataGridItem in myDataGrid.Items)
     {  
       nID = (int)myDataGrid.DataKeys[oDataGridItem.ItemIndex];//-----提示错误处

    chk= (CheckBox)oDataGridItem.FindControl("chk");
    if(chk.Checked)   
    {   
        kindsinfo.updateindetailkinds(nID,API.getInt32(catalogueList.SelectedValue),API.getInt32(kindsList.SelectedValue)); ...................
    修改后存在错误:索引超出范围。必须为非负值并小于集合大小。参数名: index 
    高手门帮忙看看
      

  7.   

    我也想实现这样的功能,用checkboxlist选择表中的多行,然后显示在表中,不知道怎么实现好呢
      

  8.   

    for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
                if (cbox.Checked == true)
                {
                   nID=(int)GridView1.Rows[i].Cells[1].Text.ToString();
                    .........//操作
                }
            }
    试一下
      

  9.   

    不好意思,我用的datagrid控件,不是gridview
      

  10.   

    nID=(int)GridView1.Rows[i].Cells[1].Text.ToString();无法转换为int
      

  11.   

    我好像实现这个 ,不过方法很笨,直接连接数据库了,看看吧,肯定有更好的方法的
    private void Button2_Click(object sender, System.EventArgs e)
    {
    foreach (DataGridItem dgi in DataGrid1.Items )
    {
    CheckBox cb2 = (CheckBox)dgi.FindControl("CheckBox3");
    if (cb2.Checked)
    {
    int nID = int.Parse(dgi.Cells[1].Text);
    string strSql = "update tbStudentinfo set checked='"+1+"' where studentid="+nID;
    ExecuteSql (strSql);
    }
    else
    {
    int nID = int.Parse(dgi.Cells[1].Text);
    string strSql = "update tbStudentinfo set checked='"+0+"' where studentid="+nID;
    ExecuteSql (strSql);
    }
    }
    string strCon = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
    SqlConnection con = new SqlConnection(strCon);
    SqlDataAdapter da = new SqlDataAdapter("Select * from tbStudentinfo where checked='" +1+"'",strCon);
    DataSet ds = new DataSet();
    da.Fill(ds,"studentinfo");
    dgShow.DataSource = ds.Tables["studentinfo"].DefaultView;
    dgShow.DataBind();
    }
      

  12.   

    我是同时把两个DataGrid的数据绑定到一个数据库的表中,其中一个只是显示选择列和ID列,另一个显示所有的信息,同时连接的数据库,我觉得用DataSet 数据集应该更好,但是我没有弄出来呢,希望以后有好运气
      

  13.   

    我是这样解决的,从数据库中取id值绑定到datagrid列中作为输入参数,再执行存储过程去更改数据库中想对应id号的数据
      

  14.   

    看了下楼住贴出来的代码,找不到问题,
    楼住能不能把当checkbox被选中后,
    如何获取key和对应的数据库操作也帖出来看看
      

  15.   

    看看吧:
    for (int i = 0; i < myDataGrid.Items.Count; i++)
    {
    CheckBox chk = (CheckBox)myDataGrid.Items[i].FindControl("chk");
    if (chk.Checked)
    {
    Label lbl = (Label)myDataGrid.Items[i].Cells[1].FindControl("label10");//最重要的一行,label10取要修改数据库中行的id
    string nID= lbl.Text;
    try
    {
       kindsinfo.updateindetailkinds(nID,API.getInt32(catalogueList.SelectedValue),API.getInt32(kindsList.SelectedValue));
       ........