Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownList problem 1

Status
Not open for further replies.

nnmmss72

Programmer
May 14, 2006
110
IR
i have a DropDownList on aspx page

<asp:DropDownList id="ProdType" runat="server" CssClass="HomeText" AutoPostBack="true"></asp:DropDownList>

which i have filled it up in page_load

private void Page_Load(object sender, System.EventArgs e)
{
String Qid=Request.QueryString["id"];
String SelCmd="Select * from TblFRProduct";
SqlCommand myCommand=new SqlCommand(SelCmd,myConnection);
myCommand.Connection.Open();
SqlDataReader dr=myCommand.ExecuteReader();
ProdType.DataTextField="Prod_Name";
ProdType.DataValueField="Prod_Id";
ProdType.DataSource=dr;
ProdType.DataBind();
dr.Close();
myCommand.Connection.Close();
}

i want whenever the selecteditem in DropDownList has been changed the page should be redirected to itself with a querystring. so i did

private void ProdType_SelectedIndexChanged(object sender, System.EventArgs e)
{
String Str="memacc.aspx?id="+ProdType.SelectedItem.Value;
Response.Redirect(Str);
}

suppose the dropdownlist has 5 items
1-a
2-b
3-c
4-d
5-e

at first time a is selected and now i select item 3 so i should i have
Response.Redirect("memacc.aspx?id=3");

but i always have memacc.aspx?id=1
always the first item has been shown as the selected item. any idea for that?
 
Check for a postback on the page load as at the moment you are binding the data every time the page loads


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top