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

[Solved] grid filter labels

3 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Nov 2009, 04:32 PM
Hi,
        I was wondering if there was any way that with the grid filtering, it would be possible to display a label of some sort next to/above/below the filter that would show which filter option the user has chosen (e.g. contains, equal to, beginswith etc)

Thanks

Robert

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 11 Nov 2009, 06:43 AM
Hello Robert,

I tried adding Label control beside each filtertextbox and set the text according to current filter function in order to achieve the functionality. Here is my code.

C#:
 
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if( e.Item is GridFilteringItem) 
        { 
            GridFilteringItem filterItem = (GridFilteringItem)e.Item;             
            foreach (GridColumn col in RadGrid1.MasterTableView.Columns) 
            { 
                Label lbl = new Label(); 
                lbl.ID = col.UniqueName.ToString() + "Filter"
                filterItem[col.UniqueName].Controls.Add(lbl); 
            } 
        } 
    } 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if(check) 
        { 
            GridFilteringItem filterItem = (GridFilteringItem)RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0]; 
            Label lbl = (Label)filterItem.FindControl((colName) + "Filter"); 
            lbl.Text = filter; 
        } 
    } 
    string colName, filter; 
    bool check = false;          
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == RadGrid.FilterCommandName) 
        { 
            Pair filterPair = (Pair)e.CommandArgument; 
            colName = filterPair.Second.ToString(); 
            filter = filterPair.First.ToString(); 
            check = true
        } 
    } 

Regards,
Shinu.
0
Mark
Top achievements
Rank 1
answered on 23 Nov 2009, 04:08 PM
Shinu,
           Did you have to change the source code of the grid itself as this doesn't compile when putting the code into the code behind of a form. Also are we allowed to change the Telerik source code.

Thanks

Robert
0
Sebastian
Telerik team
answered on 26 Nov 2009, 01:34 PM
Hello Robert,

The code snippet provided by Shinu looks correct. What type of errors you receive when you plug it on your page? I will appreciate if you share the stack trace of these exceptions to assist you address them.

You can change the source code of the controls, however thus you are not entitled to receive support concerning the modifying codebase and you will need to re-apply the chages manually for each future upgrade of RadControls for ASP.NET AJAX.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or