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

[Solved] Filter on template calculated column

1 Answer 205 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 13 Jul 2009, 04:13 PM
I have a radgrid where I generate a template column which has a checkbox as it's itemtemplate. The checkbox is checked in the codebehind if another field is prefixed with certain characters. I have included the code below. I want to know if there is a way to filter this column either saying is checked, or even is not empty?

Here is the aspx:
<telerik:GridTemplateColumn UniqueName="webLinkedContent" HeaderText="Web linked" 
            <ItemTemplate> 
                <asp:CheckBox ID="webLinkedContent" Enabled="false" runat="server" /> 
            </ItemTemplate> 
        </telerik:GridTemplateColumn> 
 and here is the c#:

  protected void sourcesGrid_itemDataBound(object sender, GridItemEventArgs e) 
        { 
            if ((e.Item is GridDataItem)) 
            { 
                GridDataItem dataItem = (GridDataItem)e.Item; 
                string psSourceCd = ((System.Data.DataRowView)(((Telerik.Web.UI.GridItem)(dataItem)).DataItem)).Row.ItemArray[9].ToString(); 
                if (psSourceCd.Length > 4) 
                { 
                    string beginning = psSourceCd.Substring(0, 4); 
                    if (beginning == "SPD_"
                    { 
                        CheckBox chkbx = dataItem["webLinkedContent"].FindControl("webLinkedContent"as CheckBox; 
                        chkbx.Checked = true
                    } 
                } 
 
            } 
        } 

Thanks



1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 16 Jul 2009, 12:28 PM
Hello Laura,

The approach you can take is to implement your GridTemplateColumn's FilterTemplate to define your own filter controls. These controls can get the required filter options and set RadGrid.MasterTableView's FilterExpression to apply the filter.

If you need to check not only if your checkbox value is true or false, but also if it has been set, a checkbox control in the column header will not be enough, as it can have only two possible values. You can use a DropDownList or RadComboBox to achieve three-option filtering (true, false, both).

You can find attached a small web site I have created demonstrating this approach. You can see how I autopostback with my DropDownList and specify the FilterExpression to apply filtering.

Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or