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

Partial match in combo: how to get that entry

2 Answers 164 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tomica
Top achievements
Rank 2
Tomica asked on 20 May 2011, 09:55 PM
I am using a combo to perform a "contains" search on titles of publications.

There are cases where I do not want to have the user select a single publication.

I would like to just accept what they type in for a partial match, and then have a button that sets a SQL select to match all titles in the current combo entry.

I tested by entering three characters, but on the code-behind I don't know how to retrieve what was entered, as there is nothing "selected".

How do I grab that entry, preferably without any complicated client-side coding.
..............
The combo is bound to a SQL datasource and has automatic load on demand enabled.

Per the online help pages, I think "the control cannot be validated by value out of the box..." is relevant, but I cannot quite understand the client logic, as it pertains to getting beyond "out of the box..." on the server.

RadComboBox can be easily validated against the Text of its items. This is by design. 
  
The control cannot be validated by value out of the box. The combobox is a composite control, its input area being essentially a <input type"text" ...> DOM element. The .value property of this DOM element corresponds to the actual text being written inside the textbox. This is 

2 Answers, 1 is accepted

Sort by
0
Accepted
Kalina
Telerik team
answered on 25 May 2011, 03:27 PM
Hi Tomica,

As I understand - you want to get the text entered in RadComboBox and perform a SQL Query in order to populate the control with items.
To achieve this you can use Load On Demand and the RadComboBox.Text property:
<telerik:RadComboBox ID="RadComboBox1" runat="server"
    EnableLoadOnDemand="true"
    DataTextField="name" DataValueField="id"
    OnItemsRequested="RadComboBox1_ItemsRequested">
</telerik:RadComboBox>

protected void RadComboBox1_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
 
        string textEntered = RadComboBox1.Text;
        // perform sql query ...
 
    }

Please note that RadComboBox items loaded via Load On Demand are not accessible at server-side - that is why you need to use the Text property.
You can find more details about this topic here.

All the best,
Kalina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Tomica
Top achievements
Rank 2
answered on 25 May 2011, 07:01 PM
Yes, this works, although in a slightly different context, as I'm using the automatic load on demand option.

The vital clue was "text", and I apologize for asking such a "dumb" question, which in effect was
 
"How do I get the text that is entered into a combo box that is not any of the "selected" options."

Answer: "yourcombobox.text"

I think this is referred to as "Programmer's Myopia", you sometimes miss something that is beyond obvious!
Tags
ComboBox
Asked by
Tomica
Top achievements
Rank 2
Answers by
Kalina
Telerik team
Tomica
Top achievements
Rank 2
Share this question
or