insert records from one gridview to another gridview when i click the add button

Posted by Parcha under ASP.NET on 6/22/2011 | Points: 10 | Views : 3555 | Status : [Member] | Replies : 3
in my webform there are two gridviews and add button and one clear button
In first gridview afterbinding data from database i have to placed check box,and header checkbox in firstgridview
so when i check the checkboxes and when i clck the add button the selected records should be added to second gridview and when i check the header checkbox all records should displyed in second gridview
and when i click the clear button records in second grid view should be cleared
how to write code for this plz plz plz plz plz help me


Posted by: Meyammai on: 6/22/2011 [Member] Starter | Points: 25



place the checkbox in the item template of the grid view and make the autopostback property = true. Attach the oncheckedchanged event.
<asp:CheckBox ID="chkAdd" runat="server" AutoPostBack="true" OnCheckedChanged="chkAdd_OnCheckedChanged" />

Try to have some Add button in the screen. user should check the checkboxes and then click add, u try to add all
the rows. otherwise performance problem may occur.

public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
datatable dtrowsAdd = new datatable();

// code for creating required columns in datatable

CheckBox chkStatus = (CheckBox)sender;
GridViewRow row = (GridViewRow)chkStatus.NamingContainer;

// create new row of the datatable dtrowsAdd and assign the gridview row values to datarow
// add the new row to the dtrowsAdd datatble and keep the datatable in session.


In the Add button event handler, loop the destination gridview( where u want to add rows)
and the rows in datatable. merge this datatable with the datatable in session. then assign the datatable
as source of gridview.


Parcha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parcha on: 6/22/2011 [Member] Starter | Points: 25

i have gridviews in 0nly 0ne webf0rm
when i click checkb0x and when i click add butt0n what ever the the recrds i checked sh0uld display in anther gridview
0n 25th i have interivew my friend went t0 the interivew they asked this questi0n s0 they are asking 0nly this pr0gram wh0 ever went f0r iterivew in that c0mpany if u pr0vide me c0de i will get the j0b in that c0mpany s0 plz help me

Parcha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 6/23/2011 [Member] Starter | Points: 25

hi..refer Below links..In the links they use grid with check Box ,when the select checkbox and click button the record wil be deleted,Instead if of deleting u just Bind the record in another grid.

Parcha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response