RadGrid 自定义过滤器

发布于 2024-08-24 13:43:09 字数 2508 浏览 1 评论 0原文

我正在尝试向我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸢与 2024-08-31 13:43:09

我在某个地方看到了这个问题的解决方案。

尝试添加:
RadGrid1.EnableLinqExpressions = false;

I saw this as a fix for this question somewhere.

Try adding:
RadGrid1.EnableLinqExpressions = false;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文