drop down list question.

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 7
Reputation: stevendmar is an unknown quantity at this point 
Solved Threads: 0
stevendmar stevendmar is offline Offline
Newbie Poster

drop down list question.

 
0
  #1
Sep 18th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,582
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: drop down list question.

 
0
  #2
Sep 18th, 2007
Using the AutoPostBack, check the value of the drop down box. Something like this:
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (Page.IsPostBack)
  4. {
  5. if (DropDownList1.SelectedValue == "foo")
  6. Response.Redirect("somepage.aspx");
  7. }
  8. }
Or, if you use VB:
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. If Page.IsPostBack Then
  3. If DropDownList1.SelectedValue = "foo" Then
  4. Response.Redirect("somepage.aspx")
  5. End If
  6. End If
  7. End Sub
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 7
Reputation: stevendmar is an unknown quantity at this point 
Solved Threads: 0
stevendmar stevendmar is offline Offline
Newbie Poster

Re: drop down list question.

 
0
  #3
Sep 18th, 2007
I think I understand that, still learning codes. What does "foo" do? Thanks, I will give this a try.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 7
Reputation: stevendmar is an unknown quantity at this point 
Solved Threads: 0
stevendmar stevendmar is offline Offline
Newbie Poster

Re: drop down list question.

 
0
  #4
Sep 18th, 2007
It still sort of refreshes the page.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,582
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: drop down list question.

 
0
  #5
Sep 18th, 2007
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 =
Last edited by Infarction; Sep 19th, 2007 at 12:02 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC