简体   繁体   English

RadGrid失去过滤器值

[英]RadGrid loses Filter value

I'm using a RadGrid that i want to allow filtering for. 我正在使用允许过滤的RadGrid。 I allow filtering on each individual column but i added a button that I intend to program to APPLY ALL FILTERS. 我允许对每个单独的列进行过滤,但是我添加了一个我打算编程的按钮以应用所有过滤器。

However, after it applies the filter I lose the filter values in the filter boxes and then it rebinds again on its own and the RadGrid is reset. 但是,在应用过滤器后,我丢失了过滤器框中的过滤器值,然后再次自行重新绑定,并重置了RadGrid。 This all happens when I click the Apply filter that i created in the command item template. 当我单击在命令项模板中创建的“应用”过滤器时,所有这些都会发生。

here's some code i'm using. 这是我正在使用的一些代码。

 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();
     } 
}

It does everything it's supposed to do except after the filter the filter boxes are cleared and the Grid binds again for some strange reason and the Grid is no longer filtered. 它会执行它应该做的所有事情,除了清除过滤器框之后,由于某些奇怪的原因网格再次绑定并且网格不再被过滤。 How can I hold the value of the filter boxes (col1,col2,col3)?? 如何保存筛选器框(col1,col2,col3)的值?

Thanks in advance for any help on the subject. 在此先感谢您提供任何帮助。

You should set the FilterValue of each column seperately. 您应该分别设置每列的FilterValue Not by referencing the controls but by using a property of the GridColumn . 不是通过引用控件,而是通过使用GridColumn的属性。 You can retrieve your columns by using: 您可以使用以下方法检索列:

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

Afterwards you can the set the filter value of the column: 然后,您可以设置列的过滤器值:

clmn.CurrentFilterValue = "myFilterValue";

This should work fine if you aren't using a FilterTemplate . 如果您不使用FilterTemplate这应该可以正常工作。 If you're using a FilterTemplate , there are some extra steps. 如果您使用FilterTemplate ,那么还有一些额外的步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM