Link to home
Start Free TrialLog in
Avatar of 1jaws
1jawsFlag for United States of America

asked on

selected value problem

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;
                }
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Please try:

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

Open in new window

Avatar of 1jaws

ASKER

no this didnt work.... item.Selected shows false all the time because this combobox is shows like a textbox, it is not pulls down like regular dropdown... because of this property makes combobox looks like text box...ShowDropDownOnTextboxClick="false"
I think the following thread addresses your problem:

problem in get selectedItems when use AutoCompleteSeparator
http://www.telerik.com/community/forums/aspnet-ajax/combobox/problem-in-get-selecteditems-when-use-autocompleteseparator.aspx

If that's the case, the following code should work for you:
string comboBoxValue="" ;
string[] selectedItemsText = ddTo.Text.ToString().Split(";"); 

foreach (string text in selectedItemsText) 
{
	RadComboBoxItem item = ddTo.FindItemByText(text) as RadComboBoxItem;
	
	if (item != null)
	{
		comboBoxValue = comboBoxValue + ((comboBoxValue == "") ? "" : ",") + item.Value;
	}
} 

Open in new window

Avatar of 1jaws

ASKER

I got those errors..


Error      10      The best overloaded method match for 'string.Split(params char[])' has some invalid arguments

Error      11      Argument 1: cannot convert from 'string' to 'char[]'      

ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1jaws

ASKER

Thank you so much it works perfect!!