473,547 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reusing code for multiple GridViews on same page

77 New Member
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.
Feb 4 '09 #1
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?
Feb 4 '09 #2
stoogots2
77 New Member
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.
Feb 23 '09 #3
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub MyGlobalSortingMethod(ByVal theGridView As GridView, ByVal theSortParameters As GridviewSortEventArgs)
  2.  
  3.  'Sorting code
  4.  
  5. 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.
Feb 23 '09 #4
stoogots2
77 New Member
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.
Feb 23 '09 #5
Frinavale
9,735 Recognized Expert Moderator Expert
The "sender" parameter should be the GridView.
Feb 23 '09 #6
stoogots2
77 New Member
Insert embarrassed smile here. Thanks for your help.
Feb 23 '09 #7
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 :)
Feb 23 '09 #8
bhupinder
32 New Member
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.

Expand|Select|Wrap|Line Numbers
  1.  Protected Sub gv1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gv1.Sorting
  2.  
  3.         Dim colum As String = e.SortExpression
  4.         sorting(colum)
  5.         binddata1()
  6.  
  7.  
  8.  
  9.     End Sub
  10.  
  11.  
  12.     Function sorting(ByVal colum As String)
  13.         hiddenSortColumnLeads.Value = colum
  14.         If hiddenSortOrderLeads.Value = "asc" Then
  15.             hiddenSortOrderLeads.Value = "desc"
  16.         Else
  17.             hiddenSortOrderLeads.Value = "asc"
  18.         End If
  19.     End Function

Implement this code.
Feb 25 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1254
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...
12
467
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. ...
2
1681
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?
0
1449
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)...
3
2431
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 ?
2
1578
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.
0
940
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.
2
1190
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...
1
3102
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...
0
7435
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...
0
7947
jinu1996
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...
0
7794
tracyyun
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...
0
6030
agi2029
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...
0
5080
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...
0
3492
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...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.