MultiColumn search by different column

5 posts, 1 answers
  1. dhuss
    dhuss avatar
    120 posts
    Member since:
    Sep 2009

    Posted 01 Apr 2014 Link to this post

    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?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Apr 2014 in reply to dhuss Link to this post

    Hi,

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. dhuss
    dhuss avatar
    120 posts
    Member since:
    Sep 2009

    Posted 02 Apr 2014 in reply to Princy Link to this post

    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
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2014 in reply to dhuss Link to this post

    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.
  6. dhuss
    dhuss avatar
    120 posts
    Member since:
    Sep 2009

    Posted 03 Apr 2014 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017