DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

Grouping buttons to one event

This is a discussion on Grouping buttons to one event within the .Net Development forums, part of the Programming & Scripting category; Hi guys My scenario: i'm creating sorting on my columns, what i wanted to do is create an event for ...

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

  #1  
Old July 17th, 2008, 05:10 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 292
Rep Power: 2
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
  #2  
Old July 17th, 2008, 05:16 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,342
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
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: 292
Rep Power: 2
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
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,342
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
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: 292
Rep Power: 2
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
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,342
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
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: 292
Rep Power: 2
Shem is on a distinguished road
Default

LMAO @ ME
Reply With Quote
  #8  
Old July 17th, 2008, 06:42 AM
richyrich's Avatar
Administrator
 
Join Date: Mar 2008
Real name: Rich
Location: Somewhere only we know...
Posts: 1,342
Blog Entries: 6
Rep Power: 8
richyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to allrichyrich is a name known to all
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: 292
Rep Power: 2
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


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
addLoadListener - adding onload event in generic way Shadow Wizard JavaScript 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 06:18 PM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2