how to get the selected row index and data of a gridview when i click a button from outside of grid

Posted by Krishnamanohar under ASP.NET on 10/25/2013 | Points: 10 | Views : 7376 | Status : [Member] | Replies : 4
HI Experts,

i have a asp.net gridview in my page .i am binding the gridview in pageload. i have button outside of the gridview.
my problem is when i select a row in a gridview and click on a buttton form outside of the gridview i am not able to get the selected index and selected row.
another problem is when i select a row in a grid i am changing the backcolor of that row .but when i select the another row also color is changing for second row also at that time two rows color is chnging.i want to select only one row if i select the second row then i have to clear the first row back color.
hi experts pls help me urgent!!!!!!!
Thanks in advance
Krish




Responses

Posted by: Bandi on: 10/25/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
If the Button out of the GridView the Button parent is an other container (maybe a Form or a Panel) not the GridView.

First of all you need a reference to the GridView. If you have a variable what contains this reference you should use that. If you haven't variable, you should search the GridView:

GridView grd = this.FindControl("GridViewName");


After that you can get the GridViewRow:
GridViewRow row = grd.SelectedRow;


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 10/25/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer
http://bytes.com/topic/asp-net/answers/876464-get-rowindex-gridview-outside-gridview
http://stackoverflow.com/questions/11338829/how-to-delete-a-row-from-the-gridview-by-using-a-button-outside-the-gridview/11338911#11338911

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 10/25/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer the following link for changing row color
http://stackoverflow.com/questions/12401887/how-do-i-change-color-of-selected-row-in-the-grid-in-c-sharp-web-application

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 10/25/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
click on "Mark as Answer " if you get help from above posts;

Post us back the code in the case of issue hasn't resolved
We will try to correct the issue

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Login to post response