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.
Vx_ChemicalAsked:
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.

BodestoneCommented:
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'

0
BodestoneCommented:
sorry, cut and paste blunder: onchange="window.open(this.options[this.selectedIndex].value,'_top')"
0
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

Are:

ID: 1
Location: Here

ID: 2
Location: There

i want when i select There, to have the webpage change to There.aspx
0
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!

bklmnshCommented:
set ListBox AutoPostBack="true" to true, handle OnSelectedIndexChanged, in the event handler code use Response.Redirect("") to the page you want
0
Vx_ChemicalAuthor Commented:
ohhh i wrote listbox when i meant dropdownlist, sorry for the confusion
0
BodestoneCommented:
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'"
0
rajapandian_81Commented:
Use OnSelectedIndexChanged event of dropdownlist.
In that event write
Response.Redirect(DropDownList1.SelectedItem.Text + ".aspx") ;
0
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");
}
0
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" 

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

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

ValueToCompare="5">*</asp:CompareValidator></td>

Open in new window

0
rajapandian_81Commented:
Location is in DataTextField. So try

Response.Redirect(locationDropDown.SelectedItem.Text + ".aspx") ;
0
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.
0
rajapandian_81Commented:
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.
0

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!
0
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
C#

From novice to tech pro — start learning today.