0
votes

I've got gridview bounded to some sqldatasource.
In first column i have edit button and in GridView_SelectedIndexChanged Event I build some querystring depending on row.
I get this row like this : GridViewRow row = GridView.SelectedRow;

It works fine BUT
From time to time I filter gridView (by changing selectcommand in sqldatasource)
Filtering works fine but GridViewRow row = GridView.SelectedRow gets a row like there were all rows visible.
Example: (When i click on 2 row)
Without filters :

1
2
3
4

row.Cells[1].Text - i get 2 OK!
With filters :

1
4

row.Cells[1].Text - i get 2 <- Maybe you know how to handle that ?

1
You are getting the right result, the selected row, which is in both case the second one = 2 - abhinav pratap
OK but the row.Cells[1].Text still gives me '2' - el vis
actually you're right i edited my question. thanks - el vis
Hi pawlakppp , Please bind any unique ID in hidden field , and after selecting row ,get value of that hidden field . Thanks . - Ronak Patel
Hi @RonakPatel You're probably right, but it was 4 years ago :) - el vis

1 Answers

0
votes

I faced the same problem, but I solved by removing a function which loads sql data to gridview in page_load ie., I created a function which loads the data from sql server to gridview. when ever I select filtered Row from grid to populate to textbox, it use to populate incorrect row. The function created to load all the rows to the grid. The Filtered rows were correct, and when select and populate a row to textbox it used to get changed as it used to autopostback(refresh).