【问题标题】:RadGrid loses Filter valueRadGrid 丢失过滤器值
【发布时间】:2011-06-10 15:07:56
【问题描述】:

我正在使用我希望允许过滤的 RadGrid。我允许对每个单独的列进行过滤,但我添加了一个我打算编程为应用所有过滤器的按钮。

但是,在应用过滤器后,我会丢失过滤器框中的过滤器值,然后它会自行重新绑定,并且 RadGrid 被重置。当我单击在命令项模板中创建的应用过滤器时,这一切都会发生。

这是我正在使用的一些代码。

 protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{


if (e.CommandName == "FilterRadGrid" || e.CommandName == "Filter")
     {
         string expression = "";
         GridFilteringItem item = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
         string col1 = (item["col1 "].Controls[0] as TextBox).Text;
         string col2 = (item["col2"].Controls[0] as TextBox).Text;
         string col3= (item["col3"].Controls[0] as TextBox).Text;

             if (col1!= "")
                 expression += "([col1] LIKE \'%" + col1+ "%\')";
             if (col2!= "")
             {
                 if (expression != "")
                     expression += " AND ";
                 expression += "([col2] LIKE \'%" + col2+ "%\')";
             }
             if (col3!= "")
             {
                 if (expression != "")
                     expression += " AND ";
                 expression += "([col3] LIKE \'%" + col3+ "%\')";
             }


         RadGrid1.MasterTableView.FilterExpression = expression;
         RadGrid1.MasterTableView.Rebind();
     } 
}

它做了它应该做的所有事情,除了在过滤器之后过滤器框被清除并且网格由于某种奇怪的原因再次绑定并且不再过滤网格。 如何保存过滤器框的值(col1,col2,col3)?

在此先感谢您提供有关此主题的任何帮助。

【问题讨论】:

    标签: c# asp.net visual-studio-2010 filter radgrid


    【解决方案1】:

    您应该单独设置每一列的FilterValue。 不是通过引用控件,而是通过使用GridColumn 的属性。 您可以使用以下方法检索您的列:

    GridBoundColumn clmn = myGrid.Columns.FindByUniqueName( "theUniqueNameOfTheColumn" );
    

    之后可以设置列的过滤值:

    clmn.CurrentFilterValue = "myFilterValue";
    

    如果您不使用FilterTemplate,这应该可以正常工作。 如果您使用的是FilterTemplate,则需要执行一些额外的步骤。

    【讨论】:

    • 您如何使用过滤器模板来处理这个问题?我目前对此有疑问。
    • @Derek 我目前离开了我工作的公司,并且没有任何源代码......对不起。我已经有一段时间没有使用 Telerik 进行一些开发了,所以我恐怕帮不了你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多