Hi
I am currently trying to use a custom filter on a GridTemplateColumn based on this example http://www.telerik.com/help/aspnet-ajax/grdimplementingfilteringfortemplatecolumns.html.
This works as expected but I lose designer support in visual studio and get the following error.
Telerik.Web.UI.GridColumnCollection must have items of type 'Telerik.Web.UI.GridColumn'. 'custom:TelerikFilterColumns' is of type 'RiskRegister.CustomFilterColumns.TelerikFilterColumns'.
Can anyone shed any light on this problem. I am using version 2009.2.701.20.
Thanks
My code follows
Filter class
Markup
Code behind
I am currently trying to use a custom filter on a GridTemplateColumn based on this example http://www.telerik.com/help/aspnet-ajax/grdimplementingfilteringfortemplatecolumns.html.
This works as expected but I lose designer support in visual studio and get the following error.
Telerik.Web.UI.GridColumnCollection must have items of type 'Telerik.Web.UI.GridColumn'. 'custom:TelerikFilterColumns' is of type 'RiskRegister.CustomFilterColumns.TelerikFilterColumns'.
Can anyone shed any light on this problem. I am using version 2009.2.701.20.
Thanks
My code follows
Filter class
using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.Data;namespace WebApplication2{ public class Filter : GridTemplateColumn { protected override void SetupFilterControls(TableCell cell) { RadComboBox filterCombo = new RadComboBox(); filterCombo.AutoPostBack = true; filterCombo.DataTextField = this.DataField; filterCombo.DataValueField = this.DataField; filterCombo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(filterCombo_SelectedIndexChanged); DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("Value", typeof(string)); DataRow row = dt.NewRow(); row["ID"] = 0; row["Value"] = 0; dt.Rows.Add(row); filterCombo.DataSource = dt; filterCombo.Width = this.FilterControlWidth; filterCombo.NoWrap = false; filterCombo.EmptyMessage = "No Filter"; cell.Controls.Add(filterCombo); } private void filterCombo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) { ((GridFilteringItem)(((RadComboBox)sender).Parent.Parent)).FireCommandEvent("Filter", new Pair()); } protected override void SetCurrentFilterValueToControl(TableCell cell) { base.SetCurrentFilterValueToControl(cell); if (!(this.CurrentFilterValue == "")) { ((RadComboBox)cell.Controls[0]).Items.FindItemByText(this.CurrentFilterValue).Selected = true; } } protected override string GetCurrentFilterValueFromControl(TableCell cell) { string currentValue = ((RadComboBox)cell.Controls[0]).SelectedItem.Value; this.CurrentFilterFunction = (currentValue != "") ? GridKnownFunction.EqualTo : GridKnownFunction.NoFilter; return currentValue; } }}Markup
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication2.WebUserControl1" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><%@ Register Assembly="WebApplication2" Namespace="WebApplication2" TagPrefix="custom" %><telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"> <MasterTableView DataKeyNames="ID" AutoGenerateColumns="false" AllowFilteringByColumn="True"> <Columns> <custom:Filter DataField="Value" HeaderText="Val"> <ItemTemplate> <asp:Label runat="server" ID="lblRiskArea" Text='<%# Bind("Value")%>' /> </ItemTemplate> </custom:Filter> </Columns> </MasterTableView></telerik:RadGrid>Code behind
using System;using System.Data;namespace WebApplication2{ public partial class WebUserControl1 : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("ID",typeof(int)); dt.Columns.Add("Value",typeof(string)); DataRow row = dt.NewRow(); row["ID"] = 0; row["Value"] = 0; dt.Rows.Add(row); RadGrid1.DataSource = dt; } }}