Multi-column ComboBox with Linq

2 posts, 1 answers
  1. Ahmad Jaber
    Ahmad Jaber avatar
    16 posts
    Member since:
    May 2010

    Posted 27 Feb 2013 Link to this post

    Hello 
    I used the instruction in the following linq 
    But Instead I used Linq to Sql to load the Data 
    I have 3 Columns Brand , Model and ProductID 
    When I write the first character of Brand I can get the result but I need to get the query result for Model also 


    For Example I will Write Microsoft it will list Microsoft or I will write Office 2007 then it will list Microsoft Office 2007
    I have the following code 


    <telerik:RadComboBox runat="server" ID="RadComboBox1" Height="190px" Width="420px"
                MarkFirstMatch="true"   EnableLoadOnDemand="true" 
                HighlightTemplatedItems="true"  OnItemsRequested="RadComboBox1_ItemsRequested" AutoPostBack ="False" >
                <HeaderTemplate>
                    <ul>
                        <li class="col1">Model Name</li>
                        <li class="col2">Brand</li>
                        <li class="col3">Product ID</li>
                    </ul>
                </HeaderTemplate>
                <ItemTemplate>
                    <ul>
                        <li class="col1">
                            <%# DataBinder.Eval(Container.DataItem, "ModelName")%></li>
                        <li class="col2">
                            <%# DataBinder.Eval(Container.DataItem, "Brand")%></li>
                        <li class="col3">
                            <%# DataBinder.Eval(Container.DataItem, "ProductID")%></li>
                    </ul>
                </ItemTemplate>
            </telerik:RadComboBox>


    And This is Code Behind 

    Protected Sub RadComboBox1_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
     
               
     
               
              Dim y = (From x In db.table_
              Where x.Manufacturer.Contains(RadComboBox1.Text)
                     Select New With {.Products = x.ModelName + " - " + x.Brand, _
                                      .ProductID = x.ProductID, .ModelName = x.ModelName, _
                                      .Manufacturer = x.Brand}).ToList
     
     
              RadComboBox1.DataSource = y
              RadComboBox1.DataTextField = "Products"
              RadComboBox1.DataValueField = "ProductID"
              RadComboBox1.DataBind()
          End Sub
          Protected Sub RadComboBox1_ItemDataBound(ByVal sender As Object, ByVal e As RadComboBoxItemEventArgs)
              'set the Text and Value property of every item
              'here you can set any other properties like Enabled, ToolTip, Visible, etc.
     
              e.Item.Text = (DirectCast(e.Item.DataItem, DataRowView))("ModelName").ToString()
              e.Item.Value = (DirectCast(e.Item.DataItem, DataRowView))("Brand").ToString()
          End Sub
     
          
      End Class



    How Can I do that 

  2. Answer
    Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 28 Feb 2013 Link to this post

    Hello Ahmad,

    try to add Filter="Contains". This will filter items by the text in all columns:

    <telerik:RadComboBox runat="server" ID="RadComboBox1" Height="190px" Width="420px"
                MarkFirstMatch="true"   EnableLoadOnDemand="true" Filter="Contains"
                HighlightTemplatedItems="true"  OnItemsRequested="RadComboBox1_ItemsRequested" AutoPostBack ="False" >
                <HeaderTemplate>
                    <ul>
                        <li class="col1">Model Name</li>
                        <li class="col2">Brand</li>
                        <li class="col3">Product ID</li>
                    </ul>
                </HeaderTemplate>
                <ItemTemplate>
                    <ul>
                        <li class="col1">
                            <%# DataBinder.Eval(Container.DataItem, "ModelName")%></li>
                        <li class="col2">
                            <%# DataBinder.Eval(Container.DataItem, "Brand")%></li>
                        <li class="col3">
                            <%# DataBinder.Eval(Container.DataItem, "ProductID")%></li>
                    </ul>
                </ItemTemplate>
            </telerik:RadComboBox>

    Regards,
    Hristo Valyavicharski
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top