How when i selected in dropdownlist to open next page.aspx?

Recommended Answers

All 8 Replies

The simplest way to do this is to use the AutoPostBack and OnSelectedIndexChanged properties. When AutoPostBack is set to true, the OnSelectedIndexChanged property will tell application which function to fire. From there you can check out what value was selected, and if it's an acceptable value, redirect as needed.

i.e.:

<asp:DropDownList ID="myDropDown" runat="server" AutoPostBack="true" OnSelectedIndexChanged="MyChangedValueFunction" >
</asp:DropDownList>

then in your code add some thing like

protected void MyChangedValueFunction(object sender, EventArgs e)
{
    //Stuff to redirect here
}

Hope that helps.

In dropdownlist is table from database of products, when the product selects to open a product.aspx that has pictures of the product.That is i need.

gogs85,

Seeing as I don't know the layout of your database, I am going to make some guesses, but I will let you know how I would do this.

The dropdownlist has "Text" and "Value" properties. When setting the "Text" property, use a descriptive name, "Yellow Lampshade", when setting the "Value" property, use a unique identifier from the database, hopefully the Product_Id or what ever the column is that is the primary key in the Product table.

On the post back event, you can use the "Value" property to construct a redirect url containing that unique id.

i.e.:

Response.Redirect("product.aspx?id=" + myProductDropDownList.SelectedValue);

On the page load of the product.aspx page, you can use Request.QueryString["id"] to get the value, and recover whatever information you need from the database.

Let me know if that works.

I don't understand very well have must do?

Ok.Thanks!

I have tried your code and it is working fine. It takes me to the page for the results. Thanks a lot.

Regards,

Bilal A. Khan

gogs85,

Seeing as I don't know the layout of your database, I am going to make some guesses, but I will let you know how I would do this.

The dropdownlist has "Text" and "Value" properties. When setting the "Text" property, use a descriptive name, "Yellow Lampshade", when setting the "Value" property, use a unique identifier from the database, hopefully the Product_Id or what ever the column is that is the primary key in the Product table.

On the post back event, you can use the "Value" property to construct a redirect url containing that unique id.

i.e.:

Response.Redirect("product.aspx?id=" + myProductDropDownList.SelectedValue);

On the page load of the product.aspx page, you can use Request.QueryString["id"] to get the value, and recover whatever information you need from the database.

Let me know if that works.

set autopostback=true in dropdown change event and call function on onselected change event and redirect it to new page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.