Load webpage from listbox Selection

I want to load a webpage from a listbox selection, my listbox is generated from a database.

any hints at what code i should use to accomplish this, iv searched around and havent found a C# answer for it.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Assuming you have all the code already to populate the listbox from the DB in c# then you just need to write some javascript for the onchange event of the listbox.

Somethign like onchange="window.open(this.options[this.selectedIndex].value,'_top'

sorry, cut and paste blunder: onchange="window.open(this.options[this.selectedIndex].value,'_top')"
Vx_ChemicalAuthor Commented:
As i wrote i would like a C# answer for it :)

But thanks anyway

The code for listbox and the database is already in order,

The values in the data base


ID: 1
Location: Here

ID: 2
Location: There

i want when i select There, to have the webpage change to There.aspx
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

set ListBox AutoPostBack="true" to true, handle OnSelectedIndexChanged, in the event handler code use Response.Redirect("") to the page you want
Vx_ChemicalAuthor Commented:
ohhh i wrote listbox when i meant dropdownlist, sorry for the confusion
You would still need to set the onchange event for the listbox and the end result would be that the aspx would write out javascript to the page.

I'll see if I can find the c# property for this but the onchange text would be:

onchange="location.href=this.options[this.selectedIndex].value + '.aspx'"
Use OnSelectedIndexChanged event of dropdownlist.
In that event write
Response.Redirect(DropDownList1.SelectedItem.Text + ".aspx") ;
Hamid HassanCommented:
First set the AutoPostBack="True" of DropDownList. And then

DataTable tb= new DataTable();
DropDownList1.DataSource = tb;    //dataset or datatable in which u have the data of database.
DropDownList1.DataTextField = "ID"
DropDownList1.DataValueField = "Location":

Now u have to write in SelectedIndexChanged event of DropDownList.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    Response.Redirect(DropDownList1.SelectedValue + ".aspx");
Vx_ChemicalAuthor Commented:
Thank you Coagantus

When testing the code in a secluded project it worked just as it should, however when im implmenting it into my website nothing happens, ill try and paste some of the code which im using

first my aspx.cs

protected void locationDropDown_SelectedIndexChanged(object sender, EventArgs e)
    Response.Redirect(locationDropDown.SelectedValue + ".aspx");

my aspx attached as cude

<td align="left" style="width: 160px">
                                                    Location of Access:</td>
                                                <td align="left" style="width: 179px">
                                                    <asp:DropDownList ID="locationDropDown" runat="server" AutoPostBack="True" 

                                                        DataTextField="Location" DataValueField="Id" Width="155px">
                                                    </asp:DropDownList><asp:CompareValidator ID="CompareValidator2" runat="server" 

                                                        ErrorMessage="Please select location of visit" Operator="NotEqual" 


Open in new window

Location is in DataTextField. So try

Response.Redirect(locationDropDown.SelectedItem.Text + ".aspx") ;
Vx_ChemicalAuthor Commented:
That doesnt seem to work im afraid.

There are two options in my database, lets call them Here and There for now, one has in ID of 1 and the other of 4.

It does the Autopost back, but the page doesnt change.
The problem may be your aspx page doesn't have locationDropDown_SelectedIndexChanged event.

In design page just double click the dropdown. The event locationDropDown_SelectedIndexChanged will be automatically added in aspx and aspx.cs page. Then copy the code
Response.Redirect(locationDropDown.SelectedItem.Text + ".aspx") ;
inside the event in aspx.cs page.

If you not getting the solution give details about your .net version.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vx_ChemicalAuthor Commented:
Great work, thanks for everyone involved, im still new at this but i learn something everyday!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.