+ Reply to Thread
Results 1 to 9 of 9

Thread: Grouping buttons to one event

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    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

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    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....

  3. #3
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    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

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    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.

  5. #5
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

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

    Shem

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Do you have the OnClick property set on your LinkButtons?

  7. #7
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    LMAO @ ME

  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Shem View Post
    LMAO @ ME
    I'll take that as a No....

  9. #9
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    working like a charm now dude
    thanks

+ Reply to Thread

Similar Threads

  1. adding an event for my btnDelete in repeater
    By Shem in forum .NET Development
    Replies: 13
    Last Post: July 15th, 2008, 10:33 AM
  2. addLoadListener - adding onload event in generic way
    By Shadow Wizard in forum JavaScript Code Samples
    Replies: 0
    Last Post: July 13th, 2008, 02:20 PM
  3. Command Buttons Coloring
    By alansidman in forum Microsoft Access
    Replies: 5
    Last Post: May 15th, 2008, 04:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO