Hello,
Here is my situation:
I have a RadGrid with a List<MyObject> as the datasource. The MyObject class has a property of Deleted on it which is a boolean.
My requirement is to filter to show only MyObjects in the RadGrid that have a Deleted propery of false. Hiding MyObjects that have a Deleted value of true.
For some reason I cannot figure out how to filter my RadGrid on the Deleted property.
Here are some of my attempts:
RadGrid1.MasterTableView.FilterExpression = "Deleted = false";
RadGrid1.MasterTableView.FilterExpression = "Deleted = 'false'";
RadGrid1.MasterTableView.FilterExpression = "Deleted is false";
RadGrid1.MasterTableView.FilterExpression = "NOT Deleted";
If anyone knows what I am doing wrong, please point me in the right direction.
Thanks,
TMP
Here is my situation:
I have a RadGrid with a List<MyObject> as the datasource. The MyObject class has a property of Deleted on it which is a boolean.
My requirement is to filter to show only MyObjects in the RadGrid that have a Deleted propery of false. Hiding MyObjects that have a Deleted value of true.
For some reason I cannot figure out how to filter my RadGrid on the Deleted property.
Here are some of my attempts:
RadGrid1.MasterTableView.FilterExpression = "Deleted = false";
RadGrid1.MasterTableView.FilterExpression = "Deleted = 'false'";
RadGrid1.MasterTableView.FilterExpression = "Deleted is false";
RadGrid1.MasterTableView.FilterExpression = "NOT Deleted";
If anyone knows what I am doing wrong, please point me in the right direction.
Thanks,
TMP
4 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 21 Oct 2008, 10:08 AM
Hi,
Try the following filter expression to filter on the basis of a boolean field.
RadGrid1.MasterTableView.FilterExpression = "([Deleted]=0) ";
RadGrid1.Rebind();
This will return all rows with the Deleted property false.
Thanks,
Shinu
Try the following filter expression to filter on the basis of a boolean field.
RadGrid1.MasterTableView.FilterExpression = "([Deleted]=0) ";
RadGrid1.Rebind();
This will return all rows with the Deleted property false.
Thanks,
Shinu
0

EpiqDev
Top achievements
Rank 2
answered on 21 Oct 2008, 05:55 PM
Thank you for your response, however using that filter did not work for my problem. :(
Addtionally I also tried using
RadGrid1.MasterTableView.FilterExpression = "[Deleted] = False";
after seeing this article in the documentation here.
I have gone with a workaround of using the FindAll function built into List<T> to filter the List before it hits the radGrid. So instead of using a filer expression, I use the following code.
This solution works for me.
Thanks Again,
TMP
Addtionally I also tried using
RadGrid1.MasterTableView.FilterExpression = "[Deleted] = False";
after seeing this article in the documentation here.
I have gone with a workaround of using the FindAll function built into List<T> to filter the List before it hits the radGrid. So instead of using a filer expression, I use the following code.
RadGrid1.DataSource = MyObjectList.FindAll(FindOnlyActive)
/// <summary> |
/// Finds only active MyObjects. |
/// </summary> |
/// <param name="Instance">The instance.</param> |
/// <returns></returns> |
private bool FindOnlyActive(MyObject Object) |
{ |
bool result = true; |
if (result.Deleted) |
result = false; |
return result; |
} |
This solution works for me.
Thanks Again,
TMP
0

Kamal
Top achievements
Rank 1
answered on 03 Mar 2015, 07:53 AM
Hello Shinu
I'm really having hard time setting the default filter. Same as mentioned in the initial post (tried FilterExpression in every way), but I get a yellow screen saying:
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 310: column.CurrentFilterValue = true.ToString();
Line 311:
Line 312: RadGrid1.MasterTableView.Rebind();
Line 313: }
Line 314: }
Source File: c:\PROJECTS\UPM4.0\UserPermissionManager\Applications.aspx.cs Line: 312
If I comment this line in PreRender function
//RadGrid1.MasterTableView.FilterExpression = "([Active] = " + true.ToString() + ") ";
The page loads, the filter is set as expected. But the grid is not filtered, means all rows(Active/Inactive) are shown. Below is the code blocks for reference. Please help.
----------------------------------------- starts - relevant code blocks for reference ---------------------------
public DataTable BindApplications()
{
return objApp.ListApplications().Tables[1];
}
private DataTable ApplicationsTable
{
get
{
object obj = Session["Applications"];
DataTable myDataTable = new DataTable();
if (obj != null)
myDataTable = (DataTable)obj;
else
myDataTable = BindApplications();
Session["Applications"] = myDataTable;
return myDataTable;
}
}
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = ApplicationsTable;
ApplicationsTable.PrimaryKey = new DataColumn[] { ApplicationsTable.Columns["AppID"] };
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
//Get the instance of the right type
GridDataItem dataBoundItem = e.Item as GridDataItem;
//Check the formatting condition
if (dataBoundItem["Active"].Text.ToLower() == "true")
{
dataBoundItem["Active"].Text = "YES";
dataBoundItem["Active"].ForeColor = dataBoundItem["AppName"].ForeColor = Color.Green;
dataBoundItem["Active"].Font.Bold = dataBoundItem["AppName"].Font.Bold = true;
}
else
{
dataBoundItem["Active"].Text = "NO";
dataBoundItem["Active"].ForeColor = dataBoundItem["AppName"].ForeColor = Color.Red;
}
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadGrid1.MasterTableView.FilterExpression = "([Active] = " + true.ToString() + ") ";
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Active");
column.CurrentFilterFunction = GridKnownFunction.EqualTo;
column.CurrentFilterValue = true.ToString();
RadGrid1.MasterTableView.Rebind();
}
}
----------------------------------------- ends - relevant code blocks for reference ----------------------------
I'm really having hard time setting the default filter. Same as mentioned in the initial post (tried FilterExpression in every way), but I get a yellow screen saying:
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 310: column.CurrentFilterValue = true.ToString();
Line 311:
Line 312: RadGrid1.MasterTableView.Rebind();
Line 313: }
Line 314: }
Source File: c:\PROJECTS\UPM4.0\UserPermissionManager\Applications.aspx.cs Line: 312
If I comment this line in PreRender function
//RadGrid1.MasterTableView.FilterExpression = "([Active] = " + true.ToString() + ") ";
The page loads, the filter is set as expected. But the grid is not filtered, means all rows(Active/Inactive) are shown. Below is the code blocks for reference. Please help.
----------------------------------------- starts - relevant code blocks for reference ---------------------------
public DataTable BindApplications()
{
return objApp.ListApplications().Tables[1];
}
private DataTable ApplicationsTable
{
get
{
object obj = Session["Applications"];
DataTable myDataTable = new DataTable();
if (obj != null)
myDataTable = (DataTable)obj;
else
myDataTable = BindApplications();
Session["Applications"] = myDataTable;
return myDataTable;
}
}
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = ApplicationsTable;
ApplicationsTable.PrimaryKey = new DataColumn[] { ApplicationsTable.Columns["AppID"] };
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
//Get the instance of the right type
GridDataItem dataBoundItem = e.Item as GridDataItem;
//Check the formatting condition
if (dataBoundItem["Active"].Text.ToLower() == "true")
{
dataBoundItem["Active"].Text = "YES";
dataBoundItem["Active"].ForeColor = dataBoundItem["AppName"].ForeColor = Color.Green;
dataBoundItem["Active"].Font.Bold = dataBoundItem["AppName"].Font.Bold = true;
}
else
{
dataBoundItem["Active"].Text = "NO";
dataBoundItem["Active"].ForeColor = dataBoundItem["AppName"].ForeColor = Color.Red;
}
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadGrid1.MasterTableView.FilterExpression = "([Active] = " + true.ToString() + ") ";
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Active");
column.CurrentFilterFunction = GridKnownFunction.EqualTo;
column.CurrentFilterValue = true.ToString();
RadGrid1.MasterTableView.Rebind();
}
}
----------------------------------------- ends - relevant code blocks for reference ----------------------------
0

Kamal
Top achievements
Rank 1
answered on 03 Mar 2015, 08:04 AM
Hello Shinu
Please nevermind.
Setting EnableLinqExpressions="false" solved my issue. Though I'm not sure how and what are it's internal semantics.
Please nevermind.
Setting EnableLinqExpressions="false" solved my issue. Though I'm not sure how and what are it's internal semantics.