This is a migrated thread and some comments may be shown as answers.

selected value

1 Answer 76 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 05 Oct 2011, 07:02 PM
I have this codes below.. On this foreach (ddTo.Items) gives me all the customers inside the combobox, all I want whatever value is selected.. How can I get that? If I have more than one item SelectedValue is not working...by just saying .selectedValue = ..

 <telerik:RadComboBox ID="ddTo" runat="server" Width="99%" Skin="Windows7" AutoCompleteSeparator=";" 
                    DataSourceID="dsSelectCustomers" DataTextField="Name" DataValueField="custID" 
                    EmptyMessage="Enter Name(s)" MarkFirstMatch="true" AllowCustomText="true"  
                    ShowDropDownOnTextboxClick="false" ShowToggleImage="false" />

 string comboBoxValue="" ;               
                foreach (RadComboBoxItem item in ddTo.Items)
                {
                    comboBoxValue = comboBoxValue + ((comboBoxValue == "") ? "" : ",") + item.Value;
                }

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 07 Oct 2011, 10:03 AM
Hi Mark ,

In order to get the selected items you should first split the text from the input based on the auto complete separator and find the corresponding items as shown below:
protected void Button1_Click(object sender, EventArgs e)
    {
        string comboText = RadComboBox1.Text;
        String[] selectedTexts = comboText.Split(';');
        List<RadComboBoxItem> selectedItems = new List<RadComboBoxItem>();
 
        foreach (var text in selectedTexts)
        {
            selectedItems.Add(RadComboBox1.Items.FindItemByText(text));
        }
 
    }


The ASPX code is as follows:
<telerik:RadComboBox ID="RadComboBox1" runat="server" Width="50%" Skin="Windows7" AutoCompleteSeparator=";"
                    EmptyMessage="Enter Name(s)" MarkFirstMatch="true" AllowCustomText="true" 
                    ShowDropDownOnTextboxClick="false" >
            <Items>
                <telerik:RadComboBoxItem Text="Biographies"  Value="Biographies"/>
                <telerik:RadComboBoxItem Text="Children's Books" Value="Children's Books" runat="server"/>
                <telerik:RadComboBoxItem Text="Computers � Internet" Value="Computers � Internet" runat="server"/>
                <telerik:RadComboBoxItem Text="Cooking" Value="Cooking" runat="server"/>
                <telerik:RadComboBoxItem Text="History" Value="History" runat="server"/>
                <telerik:RadComboBoxItem Text="Fiction" Value="Fiction" runat="server"/>
            </Items>
        </telerik:RadComboBox>
        <asp:Button ID="Button1" Text="text" runat="server" OnClick="Button1_Click"/>

Hope this helps.

Regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ComboBox
Asked by
Mark
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or