Welcome Guest Search | Active Topics | Sign In | Register

Make ListBox Selection in C# Options
Jazzcatone
Posted: Wednesday, May 28, 2014 11:49:51 AM
Rank: Member
Groups: Member

Joined: 7/21/2007
Posts: 11
I have a ListBox that is within a DropDownTemplate of a ComboBox. Assuming there are selections in the ListBox, how do I set the selected value via C# code behind ? I am only making one selection in this case. Right now in my C# I get a null reference error. Any help or direction would be most appreciated.

Code: C#
public void GetLanguageBoxSelection()
    {
        string t = Session["language"].ToString();
        if (t == "en-ca")
        {
            //Get the ListBox object inside the DropDownTemplate
            EO.Web.ListBox LB = (EO.Web.ListBox)ComboBox1.DropDownContainer.FindControl("DropDownList_lang");

       //It errors out when trying to set the selected value
            LB.SelectedItem.Value = "en-ca";


        }
eo_support
Posted: Wednesday, May 28, 2014 8:24:28 PM
Rank: Administration
Groups: Administration

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

You would just set ComboBox1.Text = "en-ca" directly. The reason is when the drop down for a ComboBox opens, it automatically select the first item that matches the ComboBox's value. So if the ComboBox1 is empty and you open the drop down, the first item will always be selected. But as long as you set the ComboBox.Text to a value, the ListBox will automatically select a matching item. Note here it's matched by Text, not by Value.

Thanks!
Jazzcatone
Posted: Thursday, May 29, 2014 12:25:59 PM
Rank: Member
Groups: Member

Joined: 7/21/2007
Posts: 11
This worked. Thanks very much !
--JasonDrool
eo_support
Posted: Thursday, May 29, 2014 5:18:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Great. Please feel free to let us know if there is anything else.

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.