Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Gridview Buttons Help

  • 31-01-2008 01:28AM
    #1
    Registered Users, Registered Users 2 Posts: 325 ✭✭


    Hi

    I'm using c#, VS2005 and MySQL

    I have a gridview with a list of a number of accommodation places coming from the DB.

    Just wondering is it possible for me to put in the Button field thats available and than when one is selected it moves to the page that I want it to.

    example:
    Winter Hotel / 08712345 / Select - choosing select brings it to winter.aspx
    Summer Hotel/ 0986668/ Select - choosing select brings it to summer.aspx


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 9,206 Mod ✭✭✭✭mewso


    Far better to use a hyperlink field that links to a page using the hotel id - view.aspx?hotelid={0}
    [SIZE=2][COLOR=#0000ff]<[/COLOR][/SIZE][SIZE=2][COLOR=#800000]asp[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]:[/COLOR][/SIZE][SIZE=2][COLOR=#800000]HyperLinkField[/COLOR][/SIZE] [SIZE=2][COLOR=#ff0000]DataNavigateUrlFields[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="hotelid"[/COLOR][/SIZE] [SIZE=2][COLOR=#ff0000]DataNavigateUrlFormatString[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="~/view.aspx?hotelid={0}"[/COLOR][/SIZE] [SIZE=2][COLOR=#ff0000]Text[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]="Select"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]/>
    [/COLOR][/SIZE]
    

    Now the view.aspx page can use the hotelid to display the relevent data and you only need one page to do this instead of a seperate page for each hotel.


  • Registered Users, Registered Users 2 Posts: 325 ✭✭doyler442


    Cheers for the help.

    I had a hyperlink there alright, I was just wondering if it was possible with a button.

    Thanks


  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    You can use command buttons for this kind of thing if you want, basically, the button passes parameters to the event handler on the postback. This tutorial has a brief explanation, Google/MSDN will have more;
    http://www.eggheadcafe.com/articles/20011210.asp

    Or you can use a LinkButton control - it's rendered as a hyperlink, but exposes the same functionality as the Button.

    As musician points out, you're better having one display page that can display any hotel instead of multiple pages for different hotels, given that this is data-driven.


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    You can use the default select button and the write a trigger for the onselectionchanged event for the gridview. In that you can put the code to redirect to whatever page suits you.


  • Moderators, Science, Health & Environment Moderators Posts: 9,206 Mod ✭✭✭✭mewso


    doyler442 wrote: »
    Cheers for the help.

    I had a hyperlink there alright, I was just wondering if it was possible with a button.

    Thanks

    It's trickier to use a button. For example you could just put in a select button but then in your code behind you need to access the hotelid using datakeys or another convoluted method and this is forcing the user to post back to the same page before being redirected to the page they want. Unecessary unless you want to run other code before passing them onto the other page but again anything you might want to do could be done on the new page when it loads anyway. If you want a button then how about just using css to style the link like one.


  • Advertisement
Advertisement