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;
                }
C#ASP.NET.NET Programming

Avatar of undefined
Last Comment
1jaws
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
1jaws
Flag of United States of America image

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

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
1jaws
Flag of United States of America image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of 1jaws
1jaws
Flag of United States of America image

ASKER

Thank you so much it works perfect!!
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo