Welcome Guest Search | Active Topics | Sign In | Register

Setting the value of a listbox item Options
MJS77
Posted: Monday, July 23, 2012 8:45:10 AM
Rank: Newbie
Groups: Member

Joined: 7/23/2012
Posts: 3
Hello,

I have a combo box with a drop down template and listbox control inside it. I've populated the items in the listbox from a database table without problems (using VB code behind). My problems come when I need to set the selected value of the list box based on my data. Can anybody help?

Thanks
eo_support
Posted: Monday, July 23, 2012 9:31:33 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,201
Hi,

You need to set the ComboBox's Text property. When you set the ComboBox's Text property, it will automatically find a matching item in the ListBox and select that item.

Thanks!
MJS77
Posted: Monday, July 23, 2012 9:43:14 AM
Rank: Newbie
Groups: Member

Joined: 7/23/2012
Posts: 3
Hi,

Thanks for the quick reply! I think I'm almost there. Unfortunately this sets the combo box with the code of the combo box item rather than the description. Other than retrieving the description of the item from the database and using that, is there a way I can set the combo box description using the code? I hope that makes sense?

Thanks
eo_support
Posted: Monday, July 23, 2012 9:54:33 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,201
Hi,

I am not sure if I understood your question correctly. What do you mean by ComboBox description?

Thanks!
MJS77
Posted: Monday, July 23, 2012 10:16:17 AM
Rank: Newbie
Groups: Member

Joined: 7/23/2012
Posts: 3
Apologies, I thought that didn't read too well.

Ok, so my listbox in my combo ooks like this:
<eo:ListBox ID="List_Rep" runat="server" DataSourceID="SqlDataSource3" DataValueField="ID" DataTextField="Name"></eo:ListBox>

When I save the selected value of the combo, it saves the datavaluefield value (this is done in another page). When I try to set the value of the combo using this database value, it displays the datavaluefield instead of displaying the datatextfield.

e.g. if my listbox contains the following:
Datavaluefield Datatextfield
1 John
2 James
3 Fred

I'm saving the values 1,2,3 etc to the database but when I try to use this database value to set the value of the combo box on entry to my page, it still displays 1,2,3 instead of John,James,fred.

Does that make any more sense? Sorry, I'm not great at explaining these things.
eo_support
Posted: Monday, July 23, 2012 10:48:34 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,201
MJS77 wrote:
When I try to set the value of the combo using this database value, it displays the datavaluefield instead of displaying the datatextfield.


The only thing you can set on the ComboBox is Text. What do you mean by "try to set the value of the combo"?

As to ListBox displaying "1, 2, 3", that should not happen at all and even if it does, it should not have anything to do with the ComboBox. The only relationship between the ComboBox and the ListBox is they sync selected item.

I would recommend you try to apply the same code with JUST the ListBox and see if the problem still occurs. If it still occurs, it would appear to be a bug and we will need to look into it. The rule is the ListBox should always display DataTextField, not DataValueField.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.