• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

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;
                }
0
1jaws
Asked:
1jaws
  • 3
  • 3
1 Solution
 
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
 
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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
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
 
wdosanjosCommented:
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
 
1jawsAuthor Commented:
Thank you so much it works perfect!!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now