Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Grouping buttons to one event" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 17th, 2008, 05:10 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default Grouping buttons to one event

Hi guys

My scenario:
i'm creating sorting on my columns, what i wanted to do is create an event
for each link button, whereby i just populate the datasource with the new
sorting value.

but i have like 5 colums on the one datasource and another 5 on the other,
and to me it seems like a waste to create so many events for sorting.

so i was thinking it would be way cooler and neater if I could group my link
buttons to one event?

Is this possible, or is there another way?

Shem
Reply With Quote
Sponsored Links
  #2  
Old July 17th, 2008, 05:16 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

I think you may be able to do it like this, although it's not something I've tried before:-

Code:
Sub sortbuttons_OnClick(ByVal s As Object, ByVal e As EventArgs)
 
Dim mybutton As LinkButton = s
 
Dim sortby As String = mybutton.CommandArgument
.
.
.
.
.
End Sub
Provided the CommandArgument of each LinkButton is set to the sortby value you want and assuming you're using LinkButtons for all of them. If you're using anything else, you may have to change the object type in the instance it creates.

Like I say, I haven't tried this before, but in theory I think it should work.

Let me know how you get on....
Reply With Quote
  #3  
Old July 17th, 2008, 05:28 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

can my link buttons have diff id's and just the commandName set to sortbuttons?

or am i misunderstanding how this is supposed to work

Shem
Reply With Quote
  #4  
Old July 17th, 2008, 05:35 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Yes, they must have different ids

When the button is clicked, the object generating the call is passed to the Sub. This is then held in the variable you create As Object, for example s.

We should then be able to create an instance of a LinkButton and set it to this object (s). Then, using mybutton.CommandArgument should give us the command argument of the object that created the call.

I guess you could use either CommandName or CommandArgument. Perhaps use CommandName for the sort by variable and Command Argument as the direction variable. You could then just toggle the command argument to be either ASC or DESC as the link button is clicked each time.

Hope that makes sense.
Reply With Quote
  #5  
Old July 17th, 2008, 06:31 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

ok the sub isn't firing, I put a break point on the sub and nothing

Shem
Reply With Quote
  #6  
Old July 17th, 2008, 06:36 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Do you have the OnClick property set on your LinkButtons?
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 17th, 2008)
  #7  
Old July 17th, 2008, 06:40 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

LMAO @ ME
Reply With Quote
  #8  
Old July 17th, 2008, 06:42 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by Shem View Post
LMAO @ ME
I'll take that as a No....
Reply With Quote
  #9  
Old July 17th, 2008, 06:53 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

working like a charm now dude
thanks
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Tags
button, event

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
adding an event for my btnDelete in repeater Shem .Net Development 13 July 15th, 2008 09:33 AM
[JavaScript] addLoadListener - adding onload event in generic way Shadow Wizard Code Samples 0 July 13th, 2008 01:20 PM
Command Buttons Coloring alansidman Microsoft Access 5 May 15th, 2008 03:57 PM


All times are GMT -4. The time now is 04:06 PM.



Content Relevant URLs by vBSEO 3.2.0