Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
Whenever, wherever, whatever
  • *Experts*
Posted

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;

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...