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;
                }
1jawsAsked:
Who is Participating?
 
wdosanjosConnect With a Mentor Commented:
My bad String.Split takes chars not strings (single quotes instead of double quotes).  Here is the corrected version:

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

0
 
wdosanjosCommented:
Please try:

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

Open in new window

0
 
1jawsAuthor Commented:
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"
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
wdosanjosCommented:
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

0
 
1jawsAuthor Commented:
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[]'      

0
 
1jawsAuthor Commented:
Thank you so much it works perfect!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.