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

How to use bind List item to FilterTemplate ComboBox

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Quoc
Top achievements
Rank 1
Quoc asked on 16 Oct 2013, 05:51 PM
In my project there is a List<User> . I want to bind data in that list to FilterTemplate-Radcombobox .
Because struct of the project I can't use 
SqlDataSource . 
<
FilterTemplate>
                       <telerik:RadComboBox ID="RadComboBoxTitle" 
                           DataValueField="GroupId" Height="200px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ContactTitle").CurrentFilterValue %>'
                           runat="server" OnClientSelectedIndexChanged="TitleIndexChanged">
                           <Items>
                               <telerik:RadComboBoxItem Text="All" />
                           </Items>
                       </telerik:RadComboBox>
  </FilterTemplate>

Thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 17 Oct 2013, 04:35 AM
Hi,

Please try the sample code snippet i have used a List to bind to the radgrid,you can bind the data to RadComboBox in the code behind.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Web20" AllowFilteringByColumn="true"
    OnNeedDataSource="RadGridSitemap_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView AutoGenerateColumns="False">
        <Columns>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                <FilterTemplate>
                    <telerik:RadComboBox ID="RadComboBoxTitle" runat="server" AllowCustomText="true"
                        AppendDataBoundItems="true" OnClientSelectedIndexChanged="TitleIndexChanged">
                        <Items>
                            <telerik:RadComboBoxItem Text="All" Value="" />
                        </Items>
                    </telerik:RadComboBox>
                    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                        <script type="text/javascript">
                            function TitleIndexChanged(sender, args) {
                                var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                tableView.filter("Name", args.get_item().get_value(), "EqualTo");
                            }
                        </script>
                    </telerik:RadScriptBlock>
                </FilterTemplate>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Price" HeaderText="Price" UniqueName="Price" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGridSitemap_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
   {
       Merchant m_merchant = new Merchant();
       this.RadGrid1.DataSource = m_merchant.GetProducts();
   }
   protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridFilteringItem)
       {
           Merchant m_merchant = new Merchant();
           GridFilteringItem Item = (GridFilteringItem)e.Item;
           RadComboBox combo = (RadComboBox)Item.FindControl("RadComboBoxTitle");
           combo.DataSource = m_merchant.GetProducts();
           combo.DataTextField = "Name";
           combo.DataValueField = "Name";
           combo.DataBind();
       }
   }
   
   public class Product
   {
       private string m_name;
       private int m_price;
 
       public Product(string name, int price)
       {
           m_name = name;
           m_price = price;
       }
 
       public string Name
       {
           get
           {
               return m_name;
           }
       }
 
       public int Price
       {
           get
           {
               return m_price;
           }
       }
   }  
   public class Merchant
   {
       private List<Product> m_products;
       public Merchant()
       {
           m_products = new List<Product>();
           m_products.Add(new Product("Pen", 25));
           m_products.Add(new Product("Pencil", 30));
           m_products.Add(new Product("Notebook", 15));
       }
       public List<Product> GetProducts()
       {
           return m_products;
       }
   }

Thanks,
Princy
Tags
Grid
Asked by
Quoc
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or