Can't add value to DropDownList, only the text is being added.

B

Bodyboarder20

Im trying to dynamically add items to a DropDownList and when I add a
new ListItem to it, I can't seem to be able to pull the "Value" that I
assigned to it....

Here's the code snippet:

while(objDataReader.Read() == true)
{
string temp = objDataReader["lname"] + ", " +
objDataReader["fname"] + " " + objDataReader["mname"];
string temp2 = objDataReader["personnel_num"].ToString();
ListItem li = new ListItem(temp,temp2);
dll.Items.Add(li);
}


Later when I access the drop down list, no matter what I ask for, All
I get is the value I have listed above as temp.

I've tried accessing it these ways:

dll.SelectedItem.Text
dll.SelectedItem.Value
dll.SelectedValue

Does anyone have any ideas?

Thanks!
 
B

Bodyboarder20

Well I figured out what I was doing wrong w/ this. BUT, I have
another problem....


I'd like to copy the contents of one drop down list into another drop
down list.


This is what I have so far:
mentor.DataSource = backup.Items;
mentor.DataBind();

mentor and backup are both drop down lists and backup is already
populated.
After copying the contents, it doesn't copy the respective values
too....

Any ideas?

thank!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top