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

[Solved] problem in get selectedItems when use AutoCompleteSeparator

2 Answers 180 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sepideh Ghanbari
Top achievements
Rank 1
Sepideh Ghanbari asked on 14 Jul 2009, 07:38 AM
I have a combobox with AutoCompleteSeparator=";" and use ItemsRequested for load data ,after select multi items the Text property is correct but SelectedValue property has only last selectedItem value .How can i get SelectedItems or selectedValues in combobox?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jul 2009, 09:34 AM
Hi Sepideh,

The SelectedValue property will return the value of the last selected item if you are using AutoCompleteSeperator for radcombobox. If you need to get the values of all the selected items, you should get the text of the input field, and split the string by ";" and find the items by text (FindItemByText) to get the values of the items. See the example shown below.

C#:
 
protected void Button1_Click(object sender, EventArgs e) 
    string[] array = new string[10]; 
    string value=""
    int i =0; 
    string text = RadComboBox1.Text.ToString(); 
    for(i = 0; text.Contains(";");i++) 
    { 
        string sub = text.Split(';')[0]; 
        text = text.Substring(text.IndexOf(';')+1); 
        array[i] = (RadComboBox1.FindItemByText(sub) as RadComboBoxItem).Value.ToString(); 
    } 
    array[i] = (RadComboBox1.FindItemByText(text) as RadComboBoxItem).Value.ToString(); // Array contains selected values
Here I used an array to keep the selected item values.

-Shinu.
0
Sepideh Ghanbari
Top achievements
Rank 1
answered on 15 Jul 2009, 05:25 AM
Hi Shinu
Thanks for your reply but I use ItemsRequested event for load data and "FindItemsbyText" return null because combobox Items is null. my code is like this :
<telerik:RadComboBox ID="RadComboBox1"  AutoPostBack="true" 
                 Runat="server" ShowToggleImage="True" ShowMoreResultsBox="false" 
                    EnableLoadOnDemand="True" MarkFirstMatch="true" Width="300" Height="100"    
                DataTextField="DisplayString" DataValueField="ParticipantID" 
                HighlightTemplatedItems="true" ShowDropDownOnTextboxClick="false"                                      
                onitemsrequested="RadComboBox1_ItemsRequested"   
                CssClass="CommonText" AutoCompleteSeparator="-" AllowCustomText="false"  > 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>                     
                </telerik:RadComboBox> 
protected void RadComboBox1_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)  
        {  
            string[] text = e.Text.Split(';');  
            var list = LoadData(text[text.Length - 1]);  
            if (list != null)  
            {  
                RadComboBox1.SelectedValue = "";  
                RadComboBox1.DataSource = list;  
                RadComboBox1.DataBind();  
 
            }  
        } 
Do you have any other solution?
Tags
ComboBox
Asked by
Sepideh Ghanbari
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sepideh Ghanbari
Top achievements
Rank 1
Share this question
or