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

Multi-column ComboBox with Linq

1 Answer 79 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ahmad Jaber
Top achievements
Rank 1
Ahmad Jaber asked on 27 Feb 2013, 05:26 PM
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 

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo Valyavicharski
Telerik team
answered on 28 Feb 2013, 04:21 PM
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.
Tags
ComboBox
Asked by
Ahmad Jaber
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or