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 7454 Frinavale 9,735
Recognized Expert Moderator Expert
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 GridviewSortEve ntArgs do not specify the Gridview itself, so I'm curious how to tell the event handler which GridView to sort.
Frinavale 9,735
Recognized Expert Moderator Expert
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.
Frinavale 9,735
Recognized Expert Moderator Expert
The "sender" parameter should be the GridView.
Insert embarrassed smile here. Thanks for your help.
Frinavale 9,735
Recognized Expert Moderator Expert
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 then call it into both areas when
needed - is this a 'class' - I'm not fully up with all the terminology...
So what should I do - within the same...
|
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. I find that the second one always
is blank. I assume this is because the DataReader is read-forward only.
...
|
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 database both fields are data type DateTime.
I want both to be in format "dd/MM/yyyy"
Why is the display different, and how can I get them the same?
|
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 Edit on the gridview (same happens
when editing other gridview which is outside the datalist) all datalist
bound fields (except the gridview)...
|
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 name and gender or by city and gender ... etc ..
how am going to display the result for each search criteria ?
| |
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. What are the options on server-side. XML spreadsheet, OWC11.Spreadsheet, tried all but no success.
|
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 of records, etc. This
is exactly the same for every grid so rather than copy and paste this code
in every page, I am hoping there is a way to better...
|
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 between second gridview and the second
formview. There is also a parent-child relationship between the first
formview and the second gridview.
Does...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |