?
Solved

Load webpage from listbox Selection

Posted on 2010-03-26
13
Medium Priority
?
421 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:Vx_Chemical
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 10

Expert Comment

by:Bodestone
ID: 28668291
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
 
LVL 10

Expert Comment

by:Bodestone
ID: 28668297
sorry, cut and paste blunder: onchange="window.open(this.options[this.selectedIndex].value,'_top')"
0
 

Author Comment

by:Vx_Chemical
ID: 28668655
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 5

Expert Comment

by:bklmnsh
ID: 28669443
set ListBox AutoPostBack="true" to true, handle OnSelectedIndexChanged, in the event handler code use Response.Redirect("") to the page you want
0
 

Author Comment

by:Vx_Chemical
ID: 28670153
ohhh i wrote listbox when i meant dropdownlist, sorry for the confusion
0
 
LVL 10

Expert Comment

by:Bodestone
ID: 28670241
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
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 28670827
Use OnSelectedIndexChanged event of dropdownlist.
In that event write
Response.Redirect(DropDownList1.SelectedItem.Text + ".aspx") ;
0
 
LVL 3

Assisted Solution

by:Hamid Hassan
Hamid Hassan earned 248 total points
ID: 28676671
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
 

Author Comment

by:Vx_Chemical
ID: 28972141
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
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 28978475
Location is in DataTextField. So try

Response.Redirect(locationDropDown.SelectedItem.Text + ".aspx") ;
0
 

Author Comment

by:Vx_Chemical
ID: 28979049
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
 
LVL 12

Accepted Solution

by:
rajapandian_81 earned 252 total points
ID: 28985770
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
 

Author Closing Comment

by:Vx_Chemical
ID: 31707449
Great work, thanks for everyone involved, im still new at this but i learn something everyday!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question