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.

More C# Help

  • 15-01-2008 12:33AM
    #1
    Registered Users, Registered Users 2 Posts: 325 ✭✭


    Hi Again


    I'm just wondering could someone help me with this. I'm using VS 2005 and MySQL.

    I have a Drop Down List and button below it.

    Depending on the selection they choose, when they click the button I wish to direct them to a certain page.

    This is what I've tried so far


    protected void Button1_Click(object sender, EventArgs e)
    {
    if (DropDownList1.SelectedValue != "UCC") Response.Redirect("http://localhost:55538/Project/SearchUCC.aspx");

    else
    if (DropDownList1.SelectedValue != "CIT") Response.Redirect("http://localhost:55538/Project/SearchCIT.aspx");

    }


    Is this anything like I should have or can someone let me know what to do.


Comments

  • Moderators, Education Moderators, Technology & Internet Moderators Posts: 35,271 Mod ✭✭✭✭AlmightyCushion


    Try Response.Redirect("SearchUCC.aspx");

    That might do it for you.


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


    Yeah you see it does redirect it but the problem is when I choose CIT it still redirects to the UCC page rather than CIT


  • Moderators, Education Moderators, Technology & Internet Moderators Posts: 35,271 Mod ✭✭✭✭AlmightyCushion


    Ah that's the problem you are having.

    The problem is != means not equals. So when you select CIT the first if statement gets executed because you are saying "when dropdown is not equal to UCC redirect to UCC".

    Change the != to == and that should solve it.


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


    Hope I'm not annoying you now but that isn't working for me either - bloody frustrating


    EDIT
    Ignore that I just got it working, I forgot to take out the automatic URL I put in while I was doing other things on it.

    Cheers for you help


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    Check and see what the value of the selected item actually is.....
    what development platform are you using?

    maybe put a break point in your code, or just print out DropDownList1.SelectedValue regardless. You'd be surprised what it can be sometimes!!

    Does your list have a .toString() member?
    Maybe try that......
    if (DropDownList1.SelectedValue.ToString() == "UCC")

    But print out the value first anyway
    protected void Button1_Click(object sender, EventArgs e)
    {
        //Just Print out the value here anyway on a label or something
    
         if (DropDownList1.SelectedValue == "UCC")  
         {         
            Response.Redirect("SearchUCC.aspx");
          }
         else if (DropDownList1.SelectedValue == "CIT") 
         {
             Response.Redirect("SearchCIT.aspx");
         }
    }
    
    


  • Advertisement
Advertisement