Hi, I want to filter on "Title" like in the code but when I apply the filter my Grid disappears and filter not work.
Can you help me and tell me why it doesn't work.
This is my code.
Thx
<telerik:GridTemplateColumn AllowFiltering="true" UniqueName="Title" DataField="Title">
<ItemTemplate>
<asp:label ID="Title" Text='<%# DataBinder.Eval(Container.DataItem,"Title")%>' runat="server"></asp:label>
<asp:label ID="Description" Text='<%# DataBinder.Eval(Container.DataItem,"Description")%>' runat="server"></asp:label>
</ItemTemplate>
</telerik:GridTemplateColumn>
Can you help me and tell me why it doesn't work.
This is my code.
Thx
<telerik:GridTemplateColumn AllowFiltering="true" UniqueName="Title" DataField="Title">
<ItemTemplate>
<asp:label ID="Title" Text='<%# DataBinder.Eval(Container.DataItem,"Title")%>' runat="server"></asp:label>
<asp:label ID="Description" Text='<%# DataBinder.Eval(Container.DataItem,"Description")%>' runat="server"></asp:label>
</ItemTemplate>
</telerik:GridTemplateColumn>
8 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Sep 2013, 04:44 AM
Hello,
Please use Grid - Advanced Data Binding/DataSource Control(SqlDataSource/LinqDataSource..etc) method to bind data in grid.
Thanks,
Jayesh Goyani
Please use Grid - Advanced Data Binding/DataSource Control(SqlDataSource/LinqDataSource..etc) method to bind data in grid.
Thanks,
Jayesh Goyani
0
Wisedead
Top achievements
Rank 1
answered on 19 Sep 2013, 07:16 AM
Hello,
I don't use Control(SqlDataSource/LinqDataSource..etc).
I'm using a List of object as datasource and in my code I have:
List<object> datasource = new List<object>();
RadGrid1.DataSource = datasource;
RadGrid1.DataBind();
must I use OnNeedDataSource For filtering?
Thx
I don't use Control(SqlDataSource/LinqDataSource..etc).
I'm using a List of object as datasource and in my code I have:
List<object> datasource = new List<object>();
RadGrid1.DataSource = datasource;
RadGrid1.DataBind();
must I use OnNeedDataSource For filtering?
Thx
0
Princy
Top achievements
Rank 2
answered on 19 Sep 2013, 08:34 AM
Hi ,
You can bind List of Objects as well, using NeedDataSource event.
Note:You should never call the Rebind() method in a NeedDataSource event handler.You should never call DataBind() as well when using advanced data binding through NeedDataSource.
ASPX:
C#:
Thanks,
Princy
You can bind List of Objects as well, using NeedDataSource event.
Note:You should never call the Rebind() method in a NeedDataSource event handler.You should never call DataBind() as well when using advanced data binding through NeedDataSource.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"> <MasterTableView> <Columns> <telerik:GridBoundColumn DataField="" HeaderText="MyHeaderText"> </telerik:GridBoundColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { List<string> data = new List<string> { "a", "b", "c" }; RadGrid1.DataSource = data; }Thanks,
Princy
0
Wisedead
Top achievements
Rank 1
answered on 19 Sep 2013, 10:03 AM
I know but I'm not using telerik:GridBoundColumn but GridTemplateColumn because I want to put in two labels in the Template
How Can I do?
Thx
How Can I do?
Thx
0
Princy
Top achievements
Rank 2
answered on 19 Sep 2013, 11:12 AM
Hi ,
Please have a look at the sample code snippet that i tried,works fine at my end.When filtering it filters on the basis of a single DataField,hence Filtering can be done only on Single column.
ASPX:
C#:
Thanks,
Princy
Please have a look at the sample code snippet that i tried,works fine at my end.When filtering it filters on the basis of a single DataField,hence Filtering can be done only on Single column.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="true"> <MasterTableView> <Columns> <telerik:GridTemplateColumn AllowFiltering="true" UniqueName="Name" DataField="Name"> <ItemTemplate> <asp:Label ID="Name" Text='<%# DataBinder.Eval(Container.DataItem,"Name")%>' runat="server"></asp:Label> <asp:Label ID="Price" Text='<%# DataBinder.Eval(Container.DataItem,"Price")%>' runat="server"></asp:Label> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { Merchant m_merchant = new Merchant(); this.RadGrid1.DataSource = m_merchant.GetProducts(); } 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
0
Wisedead
Top achievements
Rank 1
answered on 19 Sep 2013, 02:03 PM
I have the same behaviour=> not filtering.
This is my code:
<telerik:RadGrid ID="RadGridSitemap" runat="server" Skin="Web20" CellSpacing="0" GridLines="None"
OnItemDataBound="RadGridSitemap_ItemDataBound"
OnItemCommand="RadGridSitemap_ItemCommand" OnSelectedIndexChanged="RadGridSitemap_SelectedIndexChanged"
ClientSettings-EnablePostBackOnRowClick="true" AllowSorting="True" OnInit="RadGridSitemap_Init" AllowFilteringByColumn="true" Width="250px" OnNeedDataSource="RadGridSitemap_NeedDataSource">
<MasterTableView EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="false"
AutoGenerateColumns="False">
<NoRecordsTemplate>
No Data Found.
</NoRecordsTemplate>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn DataField="LongName" UniqueName="LongName" AllowFiltering="true">
<ItemTemplate>
<div>
<asp:Label ID="LongName" Text=''
<%# DataBinder.Eval(Container.DataItem,"LongName")%>' runat="server"></asp:Label>
</div>
<div>
<asp:Label ID="Description" Text=''
<%# DataBinder.Eval(Container.DataItem,"Description")%>'
runat="server"></asp:Label>
</div>
</ItemTemplate>
</telerik:GridTemplateColumn>
</ItemTemplate>
<ItemStyle Width="25px"></ItemStyle>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
This is my code:
<telerik:RadGrid ID="RadGridSitemap" runat="server" Skin="Web20" CellSpacing="0" GridLines="None"
OnItemDataBound="RadGridSitemap_ItemDataBound"
OnItemCommand="RadGridSitemap_ItemCommand" OnSelectedIndexChanged="RadGridSitemap_SelectedIndexChanged"
ClientSettings-EnablePostBackOnRowClick="true" AllowSorting="True" OnInit="RadGridSitemap_Init" AllowFilteringByColumn="true" Width="250px" OnNeedDataSource="RadGridSitemap_NeedDataSource">
<MasterTableView EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="false"
AutoGenerateColumns="False">
<NoRecordsTemplate>
No Data Found.
</NoRecordsTemplate>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn DataField="LongName" UniqueName="LongName" AllowFiltering="true">
<ItemTemplate>
<div>
<asp:Label ID="LongName" Text=''
<%# DataBinder.Eval(Container.DataItem,"LongName")%>' runat="server"></asp:Label>
</div>
<div>
<asp:Label ID="Description" Text=''
<%# DataBinder.Eval(Container.DataItem,"Description")%>'
runat="server"></asp:Label>
</div>
</ItemTemplate>
</telerik:GridTemplateColumn>
</ItemTemplate>
<ItemStyle Width="25px"></ItemStyle>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Sep 2013, 04:33 AM
Hi,
I tried your code and it's working fine at my end.The only error i faced is that in the line,
<asp:Label ID="LongName" Text='' <%# DataBinder.Eval(Container.DataItem,"LongName")%>' runat="server"></asp:Label>
You have not place the quotes properly.Here is the full code snippet that i tried,please try this and see if it filters for you.
ASPX:
C#:
Thanks,
Princy
I tried your code and it's working fine at my end.The only error i faced is that in the line,
<asp:Label ID="LongName" Text='' <%# DataBinder.Eval(Container.DataItem,"LongName")%>' runat="server"></asp:Label>
You have not place the quotes properly.Here is the full code snippet that i tried,please try this and see if it filters for you.
ASPX:
<telerik:RadGrid ID="RadGridSitemap" runat="server" Skin="Web20" CellSpacing="0" GridLines="None" ClientSettings-EnablePostBackOnRowClick="true" AllowSorting="True" AllowFilteringByColumn="true" Width="250px" OnNeedDataSource="RadGridSitemap_NeedDataSource"> <MasterTableView EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="false" AutoGenerateColumns="False"> <NoRecordsTemplate> No Data Found. </NoRecordsTemplate> <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings> <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"> </RowIndicatorColumn> <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"> </ExpandCollapseColumn> <Columns> <telerik:GridTemplateColumn DataField="Name" UniqueName="ProductName" AllowFiltering="true"> <ItemTemplate> <div> <asp:Label ID="LongName" Text='<%# DataBinder.Eval(Container.DataItem,"Name")%>' runat="server"></asp:Label> </div> <div> <asp:Label ID="Description" Text='<%# DataBinder.Eval(Container.DataItem,"Price")%>' runat="server"></asp:Label> </div> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle></telerik:RadGrid>C#:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { Merchant m_merchant = new Merchant(); this.RadGrid1.DataSource = m_merchant.GetProducts(); } 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
0
Wisedead
Top achievements
Rank 1
answered on 20 Sep 2013, 12:42 PM
Thx a lot, that filters :)