Forum guidelines
shiva kumar
selected record in gridview move to another table?
Posted By shiva kumar on 07 Apr 2012
Hi exterts,

   my req is in my gridview i have some records and each record having checkbox. if i want to select 1 checkbox and click on button that record move into another table.......

give me reply..


Re: selected record in gridview move to another table?
Posted By Senthilkumar on 08 Apr 2012  

You need to iterate the grid after selecting some rows in the main grid.

If the items are selected then it should be identified and added those results into the datatable.

        DataTable dt = new DataTable();
        DataColumn dColumn;

        dColumn = new DataColumn("ID");

        dColumn = new DataColumn("Name");

        dColumn = new DataColumn("Address");

        dColumn = new DataColumn("City");

        DataRow dRow;

        for (int i = 0; i < gvMainGrid.Rows.Count; i++)
            GridViewRow gRow = gvMainGrid.Rows[i];
            CheckBox chkItem = (CheckBox)gRow.FindControl("chkItem");
            if (chkItem.Checked)
                Label lblID = (Label)gRow.FindControl("lblID");
                Label lblName = (Label)gRow.FindControl("lblName");
                Label lblAddress = (Label)gRow.FindControl("lblAddress");
                Label lblCity = (Label)gRow.FindControl("lblCity");

                dRow = dt.NewRow();
                dRow["ID"] = lblID.Text.Trim();
                dRow["Name"] = lblName.Text.Trim();
                dRow["Address"] = lblAddress.Text.Trim();
                dRow["City"] = lblCity.Text.Trim();


After adding all the selected rows, you need to bind it into another gridview control.

gvSubGrid.DataSource = dt;

Hope this help you.

If this post is useful then mark it as "Accepted Answer"
Re: selected record in gridview move to another table?
Posted By Veera Chenna on 09 Apr 2012  
take a look at this article, it has complete tutorial on how to copy one or more checked rows from gridview to a destination table in SQL Server.

C# Corner Annual Conference 2016


Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.