Employers - Post Free Jobs
Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • selected record in gridview move to another table?
AuthorQuestion
selected record in gridview move to another table?
Posted 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..

bye


AuthorReply
Re: selected record in gridview move to another table?
Posted on: 08 Apr 2012  
Hi,

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");
        dt.Columns.Add(dColumn);

        dColumn = new DataColumn("Name");
        dt.Columns.Add(dColumn);

        dColumn = new DataColumn("Address");
        dt.Columns.Add(dColumn);

        dColumn = new DataColumn("City");
        dt.Columns.Add(dColumn);

        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();

                dt.Rows.Add(gRow);
            }
        }

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

gvSubGrid.DataSource = dt;
gvSubGrid.DataBind();

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 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.

http://technico.qnownow.com/2012/04/10/copy-rows-from-asp-net-gridview-control-to-a-sql-server-table/

Employers - Post Free Jobs

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.