Custom RadGrid Filter

I am trying to add my own filter to my RadGrid. I have a column, vendNum, which I want to allow users to filter on multiple vendNums with a comma separated list. Basically, I want to have the same functionality as the "in" operator in SQL (where vendNum in (X, Y, Z)).

I followed the tutorial on this site and came up with the following code to post in my RadGrid1_ItemCommand event.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == RadGrid.FilterCommandName) { Pair filterPair = (Pair)e.CommandArgument; switch (filterPair.Second.ToString()) { case "vendNum": TextBox tbPattern = (e.Item as GridFilteringItem)["vendNum"].Controls[0] as TextBox; if (tbPattern.Text.Contains(",")) { string[] values = tbPattern.Text.Split(','); if (values.Length >= 2) { e.Canceled = true; StringBuilder newFilter = new StringBuilder(); for (int i = 0; i < values.Length; i++) { if (i == values.Length - 1) newFilter.Append("[vendNum] = " + values[i]); else newFilter.Append("[vendNum] = " + values[i] + " OR "); } if (RadGrid1.MasterTableView.FilterExpression == "") RadGrid1.MasterTableView.FilterExpression = newFilter.ToString(); else RadGrid1.MasterTableView.FilterExpression = "((" + RadGrid1.MasterTableView.FilterExpression + ") AND (" + newFilter.ToString() + "))"; RadGrid1.Rebind(); } } break; default: break; } } } 

Doing this, however, continues to give me the "Expression Expected" error message when I try to filter the comma separated list. I can still filter one vendNum. My FilterExpression works as expected. The code does not work in the RadGrid1.Rebind() statement. Has anyone dealt with this before? Any help is appreciated.

Thanks,

Aaron

Forgot to change it

I solved this problem a few weeks ago ... I had to set the EnableLinqExpressions property to false under RadGrid.

+4
source share
1 answer

I saw this as a problem for this question.

Try adding: RadGrid1.EnableLinqExpressions = false;

+8
source

Source: https://habr.com/ru/post/1303263/


All Articles