Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

More C# Help

Options
  • 15-01-2008 1:33am
    #1
    Registered Users 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,056 Mod ✭✭✭✭AlmightyCushion


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

    That might do it for you.


  • Registered Users 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,056 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 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 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