Rajkumar R

Rajkumar R

  • NA
  • 183
  • 220.7k

Bulk insert from gridview to database

Dec 5 2011 12:11 AM
i have a gridview that contain more than 100 records, in itemtemplate i have ackeckbox for eah row. Here i want to insert all checked checkbox row to the database
 
<asp:GridView ID="GridView1" runat="server" Width="96%" PageSize="10" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowCommand="GridView1_RowCommand" >
                    <Columns>                             
            <asp:TemplateField HeaderText="Select">
                <ItemTemplate>
                    <asp:CheckBox ID="chkbox" runat="server"></asp:CheckBox>
                </ItemTemplate>
            </asp:TemplateField>
                        <asp:TemplateField HeaderText="Remark">
                <ItemTemplate>
                  <asp:Label ID="lblremark" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
                    </asp:GridView>
the above is the source code i have.

Code behind
    protected void btnview_Click(object sender, EventArgs e)
{
        GridView1.Visible = true;
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TNVKP_8;Integrated Security=True");
        con.Open();
        DataSet reportData = new DataSet();
        //reportData.ReadXml(Server.MapPath("test.xml"));
        filename = System.IO.Path.GetExtension(FileUpload1.FileName.ToString());
        if (filename == ".xml")
        {
            reportData.ReadXml(Server.MapPath(FileUpload1.FileName));
            GridView1.DataSource = reportData;
            GridView1.DataBind();           
            con.Close();
        }
        else
        {
            GridView1.Visible = false;
            Response.Write("Invalid File");
        }
}
the above code i have used to view the xml data in the gridview now i want to insert the gridview data in to database. Post solution for this
Thanks in advance

Answers (3)