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";
}
|
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!
|
Rank: Member Groups: Member
Joined: 7/21/2007 Posts: 11
|
This worked. Thanks very much ! --Jason
|
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!
|