Scooter Posted December 1, 2003 Posted December 1, 2003 I have a drop down list of about 12 part numbers and all I want to do is have it so that when you choose a part number it displays what the part description is in a label. When I try to type the code it doesn't allow me to choose the "Selected Item" without giving me an error. The only thing that it allows is "Selected Index" and when I do that nothing happens. I was just doing a simple If/ElseIf/Then statement for the code. Is that the wrong way to go about this? Quote Whenever, wherever, whatever
*Experts* Bucky Posted December 1, 2003 *Experts* Posted December 1, 2003 Is this drop-down list databound, or are you populating it dynamically? If this is so, then it's likely that in the Page_Load event you're re-binding the control again. Whenever you DataBind a list, its selected index is set back to -1. You need to insure that the page is not being posted back from the client. So, in Page_Load: if (!this.IsPostBack) { // If it's NOT postback // Bind your control(s) } You also shouldn't have to use a huge block of Ifs to set the label's text, just set it to the value of the selected item (once you get the SelectedItem to return something): Label1.Text = DropDownList1.SelectedItem.Value; Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.