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

[Solved] Search Items in Rad Multi column combobox when Enter key pressed

1 Answer 204 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
atif iqbal
Top achievements
Rank 1
atif iqbal asked on 19 Mar 2010, 11:00 AM
I make a multi column combo box. if we type in that combobox then matched values are returning. But i want that if user hit enter key only then the matched values will return and will not search items on press of any other key. Please suggest me some solution. My html and c# code is given below:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="Vista" Height="190px"  
        Width="420px" MarkFirstMatch="true" EnableLoadOnDemand="true"
        HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
        OnDataBound="RadComboBox1_DataBound" OnItemDataBound="RadComboBox1_ItemDataBound"
        OnItemsRequested="RadComboBox1_ItemsRequested"
        OnClientKeyPressing="HandkeKeyPress" >
         <HeaderTemplate>
            <ul>
                <li class="col1">Name</li>
                <li class="col2">Number</li>
                <%--<li class="col3">Title</li>--%>
            </ul>
        </HeaderTemplate>
        <ItemTemplate>
            <ul>
                <li class="col1">
                    <%# DataBinder.Eval(Container.DataItem, "Name") %></li>
                <li class="col2">
                    <%# DataBinder.Eval(Container.DataItem, "Number") %></li>
                <%--<li class="col3">
                    <%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>--%>
            </ul>
        </ItemTemplate>
        <FooterTemplate>
            A total of
            <asp:Literal runat="server" ID="RadComboItemsCount" />
            items
        </FooterTemplate>
    </telerik:RadComboBox>

and c# code is:

 private DataTable table;
    protected void Page_Load(object sender, EventArgs e)
    {
       
        DoDataBind();
    }   

    public void DoDataBind()
    {
        DataTable dt = CreateData();       
        RadComboBox1.DataSource = dt.DefaultView;
        RadComboBox1.DataBind();

    }
    protected void RadComboBox1_DataBound(object sender, EventArgs e)
    {
    
        ((Literal)RadComboBox1.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(RadComboBox1.Items.Count);
    }
    private DataTable CreateData()
    {
        table = new DataTable();
        table.Columns.Add("Name", typeof(string));
        table.Columns.Add("Number", typeof(int));
        table.Rows.Add(new object[] { "one", "1" });
        table.Rows.Add(new object[] { "two", "2" });
        table.Rows.Add(new object[] { "three", "3" });
        table.Rows.Add(new object[] { "four", "4" });
        table.Rows.Add(new object[] { "five", "5" });
        table.Rows.Add(new object[] { "six", "6" });
        return table;
    }
    protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {

        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Number", typeof(int));
        DataRow[] foundRows;
        foundRows = table.Select("Name LIKE '" + e.Text + "%'");
        foreach (DataRow dr in foundRows)
        {

            dt.ImportRow(dr);
        }
        RadComboBox1.DataSource = dt;
        RadComboBox1.DataBind();
    }

    protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
    {
        e.Item.Text = ((DataRowView)e.Item.DataItem)["Name"].ToString() + " (" +((DataRowView)e.Item.DataItem)["Number"].ToString() +")";
        e.Item.Value = ((DataRowView)e.Item.DataItem)["Number"].ToString();
    }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Mar 2010, 11:21 AM
Tags
ComboBox
Asked by
atif iqbal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or