944,144 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 4402
  • ASP.NET RSS
Sep 18th, 2007
0

drop down list question.

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stevendmar is offline Offline
11 posts
since Sep 2007
Sep 18th, 2007
0

Re: drop down list question.

Using the AutoPostBack, check the value of the drop down box. Something like this:
c# Syntax (Toggle Plain Text)
  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:
VB Syntax (Toggle Plain Text)
  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
Reputation Points: 683
Solved Threads: 53
Posting Virtuoso
Infarction is offline Offline
1,580 posts
since May 2006
Sep 18th, 2007
0

Re: drop down list question.

I think I understand that, still learning codes. What does "foo" do? Thanks, I will give this a try.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stevendmar is offline Offline
11 posts
since Sep 2007
Sep 18th, 2007
0

Re: drop down list question.

It still sort of refreshes the page.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stevendmar is offline Offline
11 posts
since Sep 2007
Sep 18th, 2007
0

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 =
Last edited by Infarction; Sep 19th, 2007 at 12:02 am.
Reputation Points: 683
Solved Threads: 53
Posting Virtuoso
Infarction is offline Offline
1,580 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Printing of Data not window on Client Sde
Next Thread in ASP.NET Forum Timeline: Edit item event handler issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC