How can I use filter expression to filter the master table colums so that I see only the rows concerning a specific loged in user?
The code to get the userid is below :
The code to get the userid is below :
MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();
I have made the userid column invisible in the grid.
8 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 18 Nov 2008, 07:47 AM
Hello Stavros,
You can globally declare the UserID value and then pass it over to the FilterExpression as shown in the code below:
aspx:
cs:
Thanks
Princy.
You can globally declare the UserID value and then pass it over to the FilterExpression as shown in the code below:
aspx:
<telerik:GridBoundColumn DataField="userid" Visible="false" UniqueName="useridColumn"> |
</telerik:GridBoundColumn> |
cs:
string UserID; //globally declare the UserId |
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack) |
{ |
RadGrid1.MasterTableView.FilterExpression = "([useridColumn] LIKE \'%" + UserID + "%\') "; |
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("useridColumn"); |
column.CurrentFilterFunction = GridKnownFunction.EqualTo; |
column.CurrentFilterValue = UserID; |
RadGrid1.MasterTableView.Rebind(); |
} |
} |
Thanks
Princy.
0

Stavros
Top achievements
Rank 1
answered on 18 Nov 2008, 08:27 AM
I altered the code like this :
and I am getting the following message :
Exception Details: Telerik.Web.UI.ParseException: Expression expected
Source Error:
using System; |
using System.Collections; |
using System.Configuration; |
using System.Data; |
using System.Linq; |
using System.Web; |
using System.Web.Security; |
using System.Web.UI; |
using System.Web.UI.HtmlControls; |
using System.Web.UI.WebControls; |
using System.Web.UI.WebControls.WebParts; |
using System.Xml.Linq; |
using Telerik.Web.UI; |
public partial class Roles_Role2_role2main : System.Web.UI.Page |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
} |
string UserID; //globally declare the UserId |
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
MembershipUser myObject = Membership.GetUser(); |
UserID = myObject.ProviderUserKey.ToString(); |
if (!Page.IsPostBack) |
{ |
RadGrid1.MasterTableView.FilterExpression = "([advisor_id] LIKE \'%" + UserID + "%\') "; |
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("advisor_id"); |
column.CurrentFilterFunction = GridKnownFunction.EqualTo; |
column.CurrentFilterValue = UserID; |
RadGrid1.MasterTableView.Rebind(); |
} |
} |
} |
and I am getting the following message :
Expression expected
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: Telerik.Web.UI.ParseException: Expression expected
Source Error:
Line 34: column.CurrentFilterFunction = GridKnownFunction.EqualTo;
Line 35: column.CurrentFilterValue = UserID;
Line 36: RadGrid1.MasterTableView.Rebind();Line 37:
Line 38: }
|
0
Hello Stavros,
When binding to old ADO.NET objects like DataSet, DataTable, etc please turn off the grid LINQ expressions (EnableLinqExpressions=false).
Best wishes,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
When binding to old ADO.NET objects like DataSet, DataTable, etc please turn off the grid LINQ expressions (EnableLinqExpressions=false).
Best wishes,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Jayesh Goyani
Top achievements
Rank 2
answered on 30 Aug 2010, 11:03 AM
hi, Vlad
thanx for your help.
it work very well.
can u explain why "EnableLinqExpressions=True" is not working in filtering ?
thanx for your help.
it work very well.
can u explain why "EnableLinqExpressions=True" is not working in filtering ?
0
Hello jayesh,
In order to utilize LINQ expressions, you will need to define the RadGrid's FilterExpression in a different manner. Review the bottom section of this documentation topic for more details.
Best regards,
Sebastian
the Telerik team
In order to utilize LINQ expressions, you will need to define the RadGrid's FilterExpression in a different manner. Review the bottom section of this documentation topic for more details.
Best regards,
Sebastian
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

Nahji
Top achievements
Rank 1
answered on 08 Jan 2014, 05:39 PM
I am using code you replied with. The filter text is showing properly, but it is not actually filtering anything
protected void RadGrid_PreRender(object sender, System.EventArgs e)
{
string CurrentYear = DateTime.Now.Year.ToString();
if (!Page.IsPostBack)
{
radgrid.MasterTableView.FilterExpression = "([MembershipYear] = \'" + CurrentYear + "\') ";
GridColumn column = radgrid.MasterTableView.GetColumnSafe("MembershipYear");
column.CurrentFilterFunction = GridKnownFunction.EqualTo;
column.CurrentFilterValue = CurrentYear;
radgrid.MasterTableView.Rebind();
}
}
<telerik:RadGrid ID="radgrid" runat="server" AllowFilteringByColumn="True" AllowPaging="True" DataSourceID="SqlDataSource1"
AllowSorting="True" GridLines="None" OnItemCreated="RadGrid1_ItemCreated" EnableLinqExpressions="false" OnPreRender="RadGrid_PreRender">
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
<MasterTableView AutoGenerateColumns="false" BorderColor="Gray" BorderWidth="1px" GridLines="Both" >
<CommandItemSettings ExportToPdfText="Export to Pdf" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="Membership Month" DataType="System.Int32" FilterControlAltText="Filter Membership Month column"
HeaderText="Membership Month" SortExpression="Membership Month" UniqueName="MembershipMonth" HeaderStyle-Width="80px" FilterControlWidth="30px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Membership Year" DataType="System.Int32" FilterControlAltText="Filter Membership Year column"
HeaderText="Membership Year" SortExpression="Membership Year" UniqueName="MembershipYear" HeaderStyle-Width="80px" FilterControlWidth="40px">
</telerik:GridBoundColumn>
protected void RadGrid_PreRender(object sender, System.EventArgs e)
{
string CurrentYear = DateTime.Now.Year.ToString();
if (!Page.IsPostBack)
{
radgrid.MasterTableView.FilterExpression = "([MembershipYear] = \'" + CurrentYear + "\') ";
GridColumn column = radgrid.MasterTableView.GetColumnSafe("MembershipYear");
column.CurrentFilterFunction = GridKnownFunction.EqualTo;
column.CurrentFilterValue = CurrentYear;
radgrid.MasterTableView.Rebind();
}
}
<telerik:RadGrid ID="radgrid" runat="server" AllowFilteringByColumn="True" AllowPaging="True" DataSourceID="SqlDataSource1"
AllowSorting="True" GridLines="None" OnItemCreated="RadGrid1_ItemCreated" EnableLinqExpressions="false" OnPreRender="RadGrid_PreRender">
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
<MasterTableView AutoGenerateColumns="false" BorderColor="Gray" BorderWidth="1px" GridLines="Both" >
<CommandItemSettings ExportToPdfText="Export to Pdf" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="Membership Month" DataType="System.Int32" FilterControlAltText="Filter Membership Month column"
HeaderText="Membership Month" SortExpression="Membership Month" UniqueName="MembershipMonth" HeaderStyle-Width="80px" FilterControlWidth="30px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Membership Year" DataType="System.Int32" FilterControlAltText="Filter Membership Year column"
HeaderText="Membership Year" SortExpression="Membership Year" UniqueName="MembershipYear" HeaderStyle-Width="80px" FilterControlWidth="40px">
</telerik:GridBoundColumn>
0

Princy
Top achievements
Rank 2
answered on 09 Jan 2014, 05:14 AM
Hi Nahji,
I see that you have a BoundColumn with DataField="Membership Year", which contains a space between the two words, where as in the code-behind for filtering you have used "([MembershipYear] = \'" + CurrentYear + "\') ", which is without space. Please make sure you have the correct DataField Name.
ASPX:
C#:
Thanks,
Princy
I see that you have a BoundColumn with DataField="Membership Year", which contains a space between the two words, where as in the code-behind for filtering you have used "([MembershipYear] = \'" + CurrentYear + "\') ", which is without space. Please make sure you have the correct DataField Name.
ASPX:
<
telerik:GridBoundColumn
DataField
=
"MembershipYear"
UniqueName
=
"MembershipYear"
. . . >
</
telerik:GridBoundColumn
>
C#:
protected
void
RadGrid_PreRender(
object
sender, System.EventArgs e)
{
string
CurrentYear = DateTime.Now.Year.ToString();
if
(!Page.IsPostBack)
{
radgrid.MasterTableView.FilterExpression =
"([MembershipYear] = \'"
+ CurrentYear +
"\') "
;
GridColumn column = radgrid.MasterTableView.GetColumnSafe(
"MembershipYear"
);
column.CurrentFilterFunction = GridKnownFunction.EqualTo;
column.CurrentFilterValue = CurrentYear;
radgrid.MasterTableView.Rebind();
}
}
Thanks,
Princy
0

Nahji
Top achievements
Rank 1
answered on 09 Jan 2014, 04:46 PM
Thanks Princy!
That did the trick
That did the trick