RadGrid 自定义过滤器
我正在尝试向我的 RadGrid 添加自定义过滤器。我有一个列 vendNum,我希望允许用户使用逗号分隔的列表过滤多个 vendNum。基本上,我想要与 SQL 中的“in”语句相同的功能(其中 vendNum 在 (X,Y,Z) 中)。
我按照 此网站 上的教程并提出了以下代码放置在我的 RadGrid1_ItemCommand 事件中。
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;
}
}
}
但是,当我尝试使用逗号分隔列表进行过滤时,这样做会不断出现错误“需要表达式”。我仍然能够过滤单个 vendNum。我的 FilterExpression
确实按预期输出。代码在 RadGrid1.Rebind()
语句上失败。以前有人处理过这个吗?非常感谢任何帮助。
谢谢,
亚伦
忘记编辑这个
我几周前解决了这个问题...我必须在 RadGrid 下将“EnableLinqExpressions”属性设置为 false。
I'm trying to add a custom 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 the same functionality as an "in" statement in SQL (where vendNum in (X,Y,Z)).
I followed the tutorial on this site and came up with the following code to place 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, though, keeps giving me an error "Expression Expected" when I try to filter with a comma separated list. I'm still able to filter a single vendNum. My FilterExpression
does come out as expected. The code is failing on the RadGrid1.Rebind()
statement. Has anyone dealt with this before? Any help is greatly appreciated.
Thanks,
Aaron
Forgot to Edit This
I solved this problem weeks ago...I had to set the "EnableLinqExpressions" property to false under the RadGrid.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在某个地方看到了这个问题的解决方案。
尝试添加:
RadGrid1.EnableLinqExpressions = false;
I saw this as a fix for this question somewhere.
Try adding:
RadGrid1.EnableLinqExpressions = false;