I would like to reuse the code for gridview sorting for each of the several GridViews that I have on one page. I've not done this before, so I am seeking a more elegant and reusable solution than coding events for each of the 4 gridviews I have.
Reusing code for multiple GridViews on same page
Collapse
X
-
-
Ok, you've created a method that does sorting.
One of the parameters that your method requires should be a reference to the GridView that called the method.
For example:
Please note that I used ByVal in the above code.Code:Private Sub MyGlobalSortingMethod(ByVal theGridView As GridView, ByVal theSortParameters As GridviewSortEventArgs) 'Sorting code End Sub
The reason for this is because a GridView is an Object, which means that it's memory location is passed as the value....
If you're not using VB.NET, just ignore this.Comment
-
Reusing code for multiple GridViews on same page
Hi
I have already used this code. firstly , i had to face same problem. but
now is working properly. I think, your problem is same. You can make a common function and call on sorting. In this function you have to pass argument according to each gridview.
Code:Protected Sub gv1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gv1.Sorting Dim colum As String = e.SortExpression sorting(colum) binddata1() End Sub Function sorting(ByVal colum As String) hiddenSortColumnLeads.Value = colum If hiddenSortOrderLeads.Value = "asc" Then hiddenSortOrderLeads.Value = "desc" Else hiddenSortOrderLeads.Value = "asc" End If End Function
Implement this code.Last edited by Frinavale; Feb 25 '09, 03:47 PM. Reason: Added [code] tags: Please post code between [code][/code] tagsComment
Comment