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.
8 7435
Have you implemented a method that sorts which you can call when ever a GridView needs to be sorted?
I am doing "custom" sorting so yes I have. The GridviewSortEventArgs do not specify the Gridview itself, so I'm curious how to tell the event handler which GridView to sort.
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: -
Private Sub MyGlobalSortingMethod(ByVal theGridView As GridView, ByVal theSortParameters As GridviewSortEventArgs)
-
-
'Sorting code
-
-
End Sub
Please note that I used ByVal in the above code.
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.
OK, that helps, except that I don't know how to get the GridView control's name from the postback. What I am trying to do is have OnSorting point to the same method for 4 out of 5 gridviews on one page.
The "sender" parameter should be the GridView.
Insert embarrassed smile here. Thanks for your help.
No problem :)
Don't feel bad, I used to make the same mistakes when I first started using .NET.
It just takes some getting used to :)
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. -
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rob Meade |
last post by:
Hi all,
I'm in the middle of finishing a page and I've noticed that I have a chunk
of code that is used in two places - its exactly the same - I guess I can
rip this out - save it seperately and...
|
by: Thomas Scheiderich |
last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read
for each.
Is there a way to do something like below where I read the data, bind to
depCity1 and then bind to destCity2. ...
|
by: Hennie |
last post by:
I have 2 gridviews on a page, each with own SQL Datasource pointing to
different tables on same database.
In the 1st date format is "dd/MM/yyyy"
Other 1
"MM/dd/yyyy hh:mm:ss"
In the SQL...
|
by: HP |
last post by:
Hi there
I have a datalist control with some bound controls in its Item Template
and a gridview bound to one of those fields (residing also in Item
Template).
I've found out that when I click...
|
by: AishaKhalfan |
last post by:
Hi, :wave:
I have many search criteria in my program, such as:
search by name, search by age, search by gender, search by city
the user can search by name only, or by name and age,
or by...
|
by: ShaijuThomas |
last post by:
Hi guys, terribly in need of help. There are multiple gridviews on my web page. I would like the data to be downloaded in a single excel book but with multiple tabs. I don't want client-side scripts....
|
by: gvera |
last post by:
Hello,
I am having a hard time trying to get the checked values of multiple Gridviews and bind them into one Datalist.
|
by: DK |
last post by:
I have an asp.net web site which has GridViews on many pages. They are
different except they all have a common Pager Template. On the DataBound
event, I customize this template based on the number...
|
by: dan |
last post by:
Hi,
I think I need a gridview, formview, another gridview, and another formview
on a single page. There is a parent-child relationship between the first
gridview and the formview and then...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |