Here is my scenerio. I have a 2 column combobox. Column 1 holds an ID number, column 2 holds a name. The combobox text/value properties are set to the ID number so the ID number will display in the combobox. We have a client that wants the ID number to display but would like to search by the name in column 2. I know how to do the items requested event using the combobox text (e.text) as the search value. How do you use data from the 2nd column as the search criteria and have the combobox auto fill as a user starts typing a name. Is this even possible?
4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 02 Apr 2014, 04:53 AM
Hi,
Please have a look into the sample code snippet which works fine at my end.
ASPX:
C#:
Let me know if you have any concern.
Thanks,
Princy.
Please have a look into the sample code snippet which works fine at my end.
ASPX:
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RadComboBox1"
Height
=
"190px"
Width
=
"420px"
DataTextField
=
"OrderID"
DataValueField
=
"OrderID"
AllowCustomText
=
"true"
DataSourceID
=
"SqlDataSource1"
EnableLoadOnDemand
=
"true"
HighlightTemplatedItems
=
"true"
OnItemDataBound
=
"RadComboBox1_ItemDataBound"
OnItemsRequested
=
"RadComboBox1_ItemsRequested"
>
<
HeaderTemplate
>
<
ul
>
<
li
class
=
"col1"
>OrderID</
li
>
<
li
class
=
"col2"
>CustomerID</
li
>
</
ul
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
ul
>
<
li
class
=
"col1"
>
<%# DataBinder.Eval(Container.DataItem, "OrderID")%></
li
>
<
li
class
=
"col2"
>
<%# DataBinder.Eval(Container.DataItem, "CustomerID")%></
li
>
</
ul
>
</
ItemTemplate
>
</
telerik:RadComboBox
>
C#:
protected
void
RadComboBox1_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
string
sql =
"SELECT * from Orders WHERE CustomerID LIKE '"
+ e.Text +
"%'"
;
RadComboBox combo = (RadComboBox)sender;
SqlDataSource1.SelectCommand = sql;
combo.DataBind();
}
protected
void
RadComboBox1_ItemDataBound(
object
sender, RadComboBoxItemEventArgs e)
{
e.Item.Text = ((DataRowView)e.Item.DataItem)[
"OrderID"
].ToString();
e.Item.Value = ((DataRowView)e.Item.DataItem)[
"CustomerID"
].ToString();
}
Let me know if you have any concern.
Thanks,
Princy.
0
dhuss
Top achievements
Rank 1
answered on 02 Apr 2014, 02:13 PM
Your code is the same code I use for the "ItemsRequested" event. My e.text = the value that is bound to the e.item.text property, which in your code is the "OrderID". So how are you pulling a "CustomerID" from e.text
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Apr 2014, 05:04 AM
Hi,
The ItemsRequested event handler receives two arguments. One is the RadCombobox, this argument is of type object and another one is the EventArgs object. This object has a number of properties for handling the items. Text is the one of the EventArgs property of ItemsRequested event. Text property returns the text in the input area of the RadComboBox. This value is used to filter the items that are added. This value doesn't have any relation with the DataTextField property of RadComboBox.
Hope this will helps you.
Thanks,
Princy.
The ItemsRequested event handler receives two arguments. One is the RadCombobox, this argument is of type object and another one is the EventArgs object. This object has a number of properties for handling the items. Text is the one of the EventArgs property of ItemsRequested event. Text property returns the text in the input area of the RadComboBox. This value is used to filter the items that are added. This value doesn't have any relation with the DataTextField property of RadComboBox.
Hope this will helps you.
Thanks,
Princy.
0
dhuss
Top achievements
Rank 1
answered on 03 Apr 2014, 02:20 PM
Thanks Princy. I was always under the impression that e.text was the same as the datatextfield. It is always a good day when you learn something new.