How to filter GridTemplateColumns of Telerik's RadGrid

16,274

Solution 1

In order to use filtering on a Template column you need to set the DataField and add the datafield to the DataKeyNames

eg:

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="True">
    <MasterTableView DataKeyNames="ID">
        <Columns> 
            <telerik:GridTemplateColumn DataField="ID" FilterControlAltText="Filter Online column" HeaderText="Online" UniqueName="Online">
                <ItemTemplate>
                    <asp:CheckBox ID="chkOnline" runat="server" Checked='<%# CheckForOnline(Eval("ID")) %>' Enabled="False" />
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
            </telerik:GridTemplateColumn>
...
etc, etc

Solution 2

If you need filtering on an item template column make sure you set the following properties on the item template column:

DataField="FileSize" AllowFiltering="true" AutoPostBackOnFilter="true" DataType="System.String"

These two are optional if you want to hide the filter function icon: ShowFilterIcon="false" CurrentFilterFunction="Contains"

Also make sure you have filtering enabled on your radgrid.

Here's a good post about it: http://www.telerikschool.com/2011/11/textbox-in-gridtemplatecolumn.html

Solution 3

Because this is an ItemTemplate that you're building manually, you will need to filter manually. See this page of the Telerik docs: http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html

Share:
16,274
SilverLight
Author by

SilverLight

WEB DEVELOPER &amp; C# PROGRAMMER ASP.NET C# JQUERY JAVASCRIPT MICROSOFT AJAX MICROSOFT SQL SERVER VISUAL STUDIO

Updated on June 04, 2022

Comments

  • SilverLight
    SilverLight almost 2 years

    I have two GridTemplateColumns in my RadGrid. The default filtering doesn't work for me and I want to change it.

    The GridTemplateColumns are like below:

    <telerik:GridTemplateColumn FilterControlAltText="Filter Online column" HeaderText="Online"
        UniqueName="Online">
        <ItemTemplate>
            <asp:CheckBox ID="chkOnline" runat="server" Checked='<%# CheckForOnline(Eval("ID")) %>'
                Enabled="False" />
        </ItemTemplate>
        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
    </telerik:GridTemplateColumn>
    

    and the other one:

    <telerik:GridTemplateColumn FilterControlAltText="Filter FileSize column" HeaderText="FileSize"
        UniqueName="FileSize" Visible="False">
        <ItemTemplate>
            <asp:Label ID="lblFileSize" runat="server" Text='<%# Eval("FileSize") %>'></asp:Label>
        </ItemTemplate>
        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
    </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn FilterControlAltText="Filter FileSizeChange column" HeaderText="FileSize"
        UniqueName="FileSizeChange">
        <ItemTemplate>
            <asp:Label ID="lblFileSizeChange" runat="server" Text='<%# ChangeFileSize(Eval("FileSize")) %>'></asp:Label>
        </ItemTemplate>
        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
    </telerik:GridTemplateColumn>
    

    As you can see, FileSize TemplateColumn is disabled and I am using FileSizeChange instead.

    FileSize string is like (213435) -> this number shows us bytes. FileSizeChange is like (231 MB)/

    How can I write filtering for both Online and FileSizeChange GridTemplateColumns?