Writing code in button’s click event in gridview

asp.net

i have added a button control in gridview and i want to redirect
to the another page on button's click event,
and also i want to access the values of selected row in a gridview and show that values on other page on button
click event which is inside the gridview,, can anybody plz help me out in this .

Best Answer

this should be helpful: http://msdn.microsoft.com/en-us/library/bb907626.aspx

for accessing values inside RowCommand event find your row first (by index):

int index = Convert.ToInt32(e.CommandArgument);

GridViewRow row = MyGridView.Rows[index];

and then controls inside it which holds the values you need:

Label MyLabel= (Label)row.FindControl(MyLabel);

after that all you need to do is to transfer to your page and send values from your controls with it (do that with querystring):

Server.Transfer("MyPage.aspx?value="+MyLabel.Text)

here you can read more about gridview RowCommand event: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx

Related Topic