Hello,
I'm trying to render a RadGrid with default filtering as explained here. I've managed to configure the grid so that filter controls are set when the page loads, but the data in the grid is not filtered. I suspect that I've missed something simple so here's my code for you to laugh at:
ASPX
C#
If I toggle the Active column checkbox, the grid behaves as expected. I'm using RadControls for ASP.NET AJAX Q2 2013.
Thanks in advance,
Matt
I'm trying to render a RadGrid with default filtering as explained here. I've managed to configure the grid so that filter controls are set when the page loads, but the data in the grid is not filtered. I suspect that I've missed something simple so here's my code for you to laugh at:
ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
telerik:RadStyleSheetManager
id
=
"RadStyleSheetManager1"
runat
=
"server"
/>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
<
Scripts
>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.Core.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQuery.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQueryInclude.js"
/>
</
Scripts
>
</
telerik:RadScriptManager
>
<
script
type
=
"text/javascript"
>
//Put your JavaScript code here.
</
script
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
</
telerik:RadAjaxManager
>
<
div
>
<
telerik:RadGrid
ID
=
"rgdUsers"
runat
=
"server"
AutoGenerateColumns
=
"false"
AllowFilteringByColumn
=
"true"
OnNeedDataSource
=
"rgdUsers_NeedDataSource"
OnPreRender
=
"rgdUsers_PreRender"
>
<
MasterTableView
DataKeyNames
=
"Id, Active, Name, Surname"
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"ActiveColumn"
DataField
=
"Active"
HeaderText
=
"Active"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"EqualTo"
CurrentFilterValue
=
"True"
/>
<
telerik:GridBoundColumn
UniqueName
=
"NameColumn"
DataField
=
"Name"
HeaderText
=
"Name"
/>
<
telerik:GridBoundColumn
UniqueName
=
"SurnameColumn"
DataField
=
"Surname"
HeaderText
=
"Surname"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
</
html
>
C#
using
System;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
System.Configuration;
using
System.Web.Security;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Linq;
using
Telerik.Web.UI;
public
partial
class
Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
rgdUsers_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
using
(SwmpHermesEntities ent =
new
SwmpHermesEntities())
{
var Users = ent.Users.ToList();
rgdUsers.DataSource = Users;
}
}
protected
void
rgdUsers_PreRender(
object
sender, EventArgs e)
{
if
(!
this
.IsPostBack)
{
rgdUsers.MasterTableView.FilterExpression =
"([Active] = True)"
;
GridColumn activeColumn = rgdUsers.MasterTableView.GetColumnSafe(
"ActiveColumn"
);
activeColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
activeColumn.CurrentFilterValue =
"True"
;
}
}
}
If I toggle the Active column checkbox, the grid behaves as expected. I'm using RadControls for ASP.NET AJAX Q2 2013.
Thanks in advance,
Matt