I have two GridTemplateColumn
s 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
GridTemplateColumn
s?
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