Please click 'Mark as Answer' if reply assisted you.
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams
Marked as answer by cmt9000 on Sep 09, 2009 06:12 PM
Please click 'Mark as Answer' if reply assisted you.
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams
Marked as answer by cmt9000 on Sep 09, 2009 06:12 PM
cmt9000
Member
265 Points
312 Posts
listbox and hidden values?
Sep 09, 2009 04:25 PM|LINK
I have a listBox on my web form that allows users to select multiple userNames from it.
However, in order to save those selected user names to a database, I need the userID.
Is there a way of "hidding" the userID in the listBox or would I need to use another type of web form element?
Thanks
MetalAsp.Net
All-Star
112170 Points
18257 Posts
Moderator
Re: listbox and hidden values?
Sep 09, 2009 04:48 PM|LINK
A listbox allows you to specify a text & value. The text is what gets displayed and the value you set to whatever you want, say userID in your case.
pixelsyndica...
Star
7826 Points
1344 Posts
Re: listbox and hidden values?
Sep 09, 2009 04:50 PM|LINK
ListItem's in a listbox or dropdownlist or anything like that can have two values.
the VALUE (which the user doesn't see) should be the UserID
the TEXT of the items should be what the user can see and understand, like the UserNames.
<asp:ListBox ID="myListBox" runat="server">
<asp:ListItem Text="JobBob" Value="123"></asp:ListItem></asp:ListBox>
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams
cmt9000
Member
265 Points
312 Posts
Re: listbox and hidden values?
Sep 09, 2009 05:11 PM|LINK
I don't see a way to add a value...this is what I have:
If dr.HasRows Then Do While dr.Read myListBox.Items.Add(dr.Item("userName")) Loop End IfCould I do myListBox.Add.Value(dr.Item("userID")?
Thanks!
pixelsyndica...
Star
7826 Points
1344 Posts
Re: listbox and hidden values?
Sep 09, 2009 05:18 PM|LINK
myListBox.Items.Add(new ListItem("textgoeshere", "valuegoeshere"));
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." ~ Douglas Adams