column selection of GridView
-
Hello! sorry if this has been asked before, couldn't find anything. I've a gridview populated with data from database. I want to allow user to click on a column, send the action to the server which will recognize the column selected. The only actions I can see send the row which was clicked on, and not the column. For exampel this action:
protected void MainGrid\_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) string s = ((DataRowView)e.Row.DataItem).ToString(); }
Thanks for help!
-
Hello! sorry if this has been asked before, couldn't find anything. I've a gridview populated with data from database. I want to allow user to click on a column, send the action to the server which will recognize the column selected. The only actions I can see send the row which was clicked on, and not the column. For exampel this action:
protected void MainGrid\_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) string s = ((DataRowView)e.Row.DataItem).ToString(); }
Thanks for help!
I know this is not the perfect solution, but you can apply this until you find another one. Enable Sorting on the gridview and then handle the
Sorting
event. inside that you will get ae.SortExpression
. which is the Column name you clicked on. Now call some method by passing it as parameter andreturn;
. I am not sure but most probably this will work. -
Hello! sorry if this has been asked before, couldn't find anything. I've a gridview populated with data from database. I want to allow user to click on a column, send the action to the server which will recognize the column selected. The only actions I can see send the row which was clicked on, and not the column. For exampel this action:
protected void MainGrid\_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) string s = ((DataRowView)e.Row.DataItem).ToString(); }
Thanks for help!
-
I know this is not the perfect solution, but you can apply this until you find another one. Enable Sorting on the gridview and then handle the
Sorting
event. inside that you will get ae.SortExpression
. which is the Column name you clicked on. Now call some method by passing it as parameter andreturn;
. I am not sure but most probably this will work. -
thanks for the quick reply that seems to be a good approach. I tried implement it but it doesn't invoke the action when i click on the grid. have i forgot something? (I enabled sorting)
all you have to do is, AllowSorting = "true" and then handle the "Sorting" event (OnSorting="GridView1_Sorting"). and then click on the column names (it should be appeared as links) at the run time.