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

Need help w/ Custom Filter

1 Answer 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 18 Jan 2009, 04:15 AM
I'm using the RadGrid in DNN and everything works great.

However, I'm trying to implement a custom filter.  Here's what I've got:

The header of my .ascx (Notice the "Register" directive):

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="admin.ascx.cs" Inherits="DesertedRoadStudios.Modules.DiscipleHatTournament.admin" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
 
<%@ Register TagPrefix="custom" Namespace="DesertedRoadStudios.Controls" %> 
 
 

A few lines down, I have a RadGrid control with the registered control as one of my columns:

            <custom:GenderCustomFilter UniqueName="gender" DataField="gender" HeaderText="Gender" /> 
 

In the code-behind:

namespace DesertedRoadStudios.Controls  
{  
    public class GenderCustomFilter : GridBoundColumn  
    {  
        //RadGrid calls this method when it initializes the controls inside the filtering item cells  
        protected override void SetupFilterControls(TableCell cell)  
        {  
            base.SetupFilterControls(cell);  
            cell.Controls.RemoveAt(0);  
            DropDownList list = new DropDownList();  
            list.ID = "list" + this.DataField;  
 
            list.AutoPostBack = true;  
            list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);  
            list.Items.Add("Male");  
            list.Items.Add("Female");  
            cell.Controls.AddAt(0, list);  
            cell.Controls.RemoveAt(1);  
        }  
 
        void list_SelectedIndexChanged(object sender, EventArgs e)  
        {  
            GridFilteringItem filterItem = (sender as DropDownList).NamingContainer as GridFilteringItem;  
            filterItem.FireCommandEvent("Filter"new Pair("Contains"this.UniqueName));  
        }  
 
        //RadGrid calls this method when the value should be set to the filtering input control(s)  
        protected override void SetCurrentFilterValueToControl(TableCell cell)  
        {  
            base.SetCurrentFilterValueToControl(cell);  
            DropDownList list = (DropDownList)cell.Controls[0];  
            if (this.CurrentFilterValue != string.Empty)  
            {  
                list.SelectedValue = this.CurrentFilterValue;  
            }  
        }  
          
        //RadGrid calls this method to extract the filtering value from the filtering input control(s)  
        protected override string GetCurrentFilterValueFromControl(TableCell cell)  
        {  
            DropDownList list = (DropDownList)cell.Controls[0];  
            return list.SelectedValue;  
        }  
 
        protected override string GetFilterDataField()  
        {  
            return this.DataField;  
        }  
    }  
 
}  
 


Please notice a few things...

The .ascx inherits "DesertedRoadStudios.Modules.DiscipleHatTournament.admin" and the in the code-behind the public partial class "DesertedRoadStudios.Modules.DiscpleHatTournament.admin" inherits PortalModuleBase (what its suppose to inherit for DNN).

However, at the END of the code-behind, I create a new namespace "DesertedRoadStudios.Controls" in which I place the custom filter "GenderCustomFilter" that inherits the GridBoundColumn.

I thought this would be okay, but perhaps, I'm not setting up the "Register" directive correctly. Nonetheless, the control "<custom:GenderCustomFilter />" cannot be located. How do I do this correctly without having to compile classes and install them into the DNN BIN folder?

Thanks,
Joshua

1 Answer, 1 is accepted

Sort by
0
Joshua
Top achievements
Rank 1
answered on 18 Jan 2009, 04:36 AM
nevermind. got it.
Tags
Grid
Asked by
Joshua
Top achievements
Rank 1
Answers by
Joshua
Top achievements
Rank 1
Share this question
or