DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   drop down list question. (http://www.daniweb.com/forums/thread90027.html)

stevendmar Sep 18th, 2007 6:42 pm
drop down list question.
 
Using Visual Web Developer, I am wanting to use a Drop-Down list on a Web Form. I know how to use HTML to create and add items to a Drop-Down list. The problem is that I need to populate the list from a database. So I used a DropDownList control from the menu. I specify where the database is and which table and columns to use. The problem I am running into, and not seeing any fix for, is that I need to be able to select an item and automatically be linked to another page. I set a table in my DB to be a hyperlink field, but that does not seem to work. I set the AutoPost to true, but all that seems to do is refresh the page. I am guessing that it is trying to place data on the same page, but that is not what I need.

So basically, all I need is a Drop Down that gets populated from a DB, and when a item is selected in the Drop Down it links to another page. Sounds easy, huh?

I need someone who is smarter than me. Can this even be done? Please help. Thank you.

Infarction Sep 18th, 2007 9:20 pm
Re: drop down list question.
 
Using the AutoPostBack, check the value of the drop down box. Something like this:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            if (DropDownList1.SelectedValue == "foo")
                Response.Redirect("somepage.aspx");
        }
    }
Or, if you use VB:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            If DropDownList1.SelectedValue = "foo" Then
                Response.Redirect("somepage.aspx")
            End If
        End If
    End Sub

stevendmar Sep 18th, 2007 9:40 pm
Re: drop down list question.
 
I think I understand that, still learning codes. What does "foo" do? Thanks, I will give this a try.

stevendmar Sep 18th, 2007 11:17 pm
Re: drop down list question.
 
It still sort of refreshes the page.

Infarction Sep 18th, 2007 11:56 pm
Re: drop down list question.
 
foo is a value to compare against. You'll want to replace it with whatever value you have, and other values with else if statements. And I'm totally out of the habit of writing code. Those should be DropDownList.SelectedValue.Equals("foo") rather than using == and = :icon_redface:


All times are GMT -4. The time now is 7:43 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC