Copying rows from one gridview to another gridvies
hi,
am filling one gridview with values from database..then i want to copy the selected rows through checkboxes into another gridview..
below is the code in c#
DataTable dt = new DataTable();
foreach(GridViewRow dgr in GridView1.Rows)
{
if(((CheckBox)(dgr.FindControl("chkbx"))).Checked==true)
{
dt.Rows.Add(dgr);
}
GridView2.DataSource=dt;
GridView2.DataBind();
when i compile am getting Input array is longer than the number of columns in this table error message..am new to .net..any help will be greatly appreciated..
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Mar 16, 2009, 6:49 AM EDT
Hi
to find an loop through checked rows or gv1
foreach (GridViewRow objGridViewRow in ListGridView.Rows)
{
if (((CheckBox)(objGridViewRow.FindControl("AddCheckBox"))).Checked = true)
{
add as a new row to a datatable.
}
}
Bind the above datatable to gv2.
Check out the below link for more information.
http://forums.asp.net/t/1174737.aspx
Thanks -- Vijaya Kadiyala