Almighty Expert Needed!!!!!!!
Posted on 2004-08-25
I am at my wits end with attempting to retrieve the values selected for a dropdown list control. I am having no problems retrieving the text results of those values selected however; I cannot seem to get all of the values selected to show up. Only the first value of the first item selected in the dropdownlist is retrieved.
Can someone please help me discover the woes of my code?
Here is the script for the control:
<asp:listbox id="Creator" runat="server" SelectionMode="Multiple" Rows="1"></asp:listbox>
Here is the script to gather the data selected from the control:
SqlConnection conn = new SqlConnection("server=C099450d01;uid=sa;pwd=;database=tools");
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("Select UID, LastName +','+ FirstName From Employee Where UID = @UID ORDER BY LastName", conn);
foreach (ListItem myItem in Creator.Items)
if (myItem.Selected == true)
if (lblCreator.Text.Length > 0)
cmd.Parameters.Add("@UID", SqlDbType.Real).Value = Creator.SelectedValue;
lblCreator.Text += " - ";
lblCreator.Text += myItem.Text;
What is happening is that if I put a break point in the build located at the end of this script I can see that the "Creator.Items" shows me all of those selected from the ddl. However if I mouseover the "Creator.SelectedValue" I am only seeing one value where I should be seeing a value for all selected.
Any help would be greatly appreciated.