<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="检查项目详细名称"
        DataSourceID="SqlDataSource2">
        <Columns>
            <asp:TemplateField HeaderText="选择" SortExpression="ST_id">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="检查项目详细名称" HeaderText="检查项目详细名称" ReadOnly="True" SortExpression="检查项目详细名称" />
            <asp:BoundField DataField="价格" HeaderText="价格" SortExpression="价格" />
        </Columns>
    </asp:GridView>想把checkbox1勾选的记录存入另一张表,请问该如何实现?

解决方案 »

  1.   

    checkbox只有checkbox1,如何引用多条记录?
      

  2.   

        foreach (GridViewRow row in this.gvwQXLB.Rows)  
        {  
            if (((CheckBox)(row.FindControl("ckbYHQX"))).Checked == true)//当前选中的checkBox  
            {  
                Response.Write(gvwQXLB.Rows[row.RowIndex].Cells[1].Text);//获得BoundField的值  
            }  
        }  将记录插入表 LZ自己来吧.
      

  3.   


    foreach(gridviewrow thisgridviewrow  in this.gridview.rows)
    {
       checkbox thischeckbox = thisgridviewrow.findcontrol("checkbox1");
       if(thischeckbox.checked)
       {
           int id = thisgridviewrow.cells[0].text.tostring().trim();
           //--寫sql語句,插入表內就可以了
       }
    }
      

  4.   

        DataTable dt=new DataTable();
        dt.Columns.add("检查项目详细名称");
        dt.Columns.add("价格");
        foreach (GridViewRow gvr in this.GridView1.Rows)  
        {  
            if (((CheckBox)(gvr.Cells[0].FindControl("CheckBox1"))).Checked == True)  
            {  
                DataRow dr=dt.NewRow();
                dr["检查项目详细名称"]=gvr.Cells[1].Text.Trim(); 
                  dr["价格"]=gvr.Cells[2].Text.Trim();  
            }  
        } 
        dt.AcceptChanges(); 
      

  5.   

    在你保存数据的事件里,放上你对CheckBox的判断、存数据的代码
      

  6.   

    这里有你要的 http://www.olcodes.com/article/html/5207.html 好好学习啊 
      

  7.   

     foreach (GridViewRow gr in this.gridview1.Rows)  
        {  
            if (((CheckBox)(gr.FindControl("ckbYHQX"))).Checked == true)       
               {  
                string id=(this.GridView1.DataKeys[gr.DataItemIndex].Value).ToString();        }  
        }  看看gridview72例