This is a migrated thread and some comments may be shown as answers.

Default Filtering Question

2 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Kingston
Top achievements
Rank 2
David Kingston asked on 20 Oct 2009, 04:35 AM
I've read the tutorials, and how-to section.  I'm using the 2009.2.701.35 dll.
I have a RadGrid with several columns.  The important part is that one contains an EnvironmentID.  I've setup a SQL datasource that gets the info from a view in the database.  I'm trying to set up a default filter on the EnvironmentID field to filter out any with the ID of 4.  I can not get the demo code to work to save my life.  There has to be something that I'm missing.

When I compile the site it does not filter the grid.  When I look at the filter, it shows "DoesNotEqual" as the selected filter, but there is no number in the box.  And, of course, the items with an EnvironmentID of 4 are there.

When I manually input a 4 and press enter, it filters just fine.  It just does not load with the filter.

I've also tried to set the filter declaratively (just like the example), but changing the CurrentFilterFunction="NotEqualTo" and CurrentFilterValue="4" on the EnvironmentID column.  When I do that, it doesn't filter, but the 4 shows up in the box and NotEqualTo is the highlighted filter.  When I press enter, it filters just fine.

One other thing:  I've changed the column type from GridBoundColumn to GridNumericColumn with no change (and back).  I've also tried changing the datatype to system.string with no real changes either.

Based on the lack of relevant articles indicating this is broken, what am I doing wrong?

Here's the pertinent Grid stuff:
<telerik:RadGrid ID="ServerRadGrid" runat="server"   
AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True"   
AutoGenerateEditColumn="True" DataSourceID="SqlDataViewServerLookup"   
GridLines="None" EnableLinqExpressions="false"   
onprerender="ServerRadGrid_PreRender">   
 
<MasterTableView AutoGenerateColumns="False" DataKeyNames="ServerID"   
DataSourceID="SqlDataViewServerLookup" AllowFilteringByColumn="True">   
 
<RowIndicatorColumn>   
<HeaderStyle Width="20px"></HeaderStyle>   
</RowIndicatorColumn>   
<ExpandCollapseColumn>   
<HeaderStyle Width="20px"></HeaderStyle>   
</ExpandCollapseColumn>   
 
<Columns>   
<Telerik:GridBoundColumn datafield="ServerID" datatype="System.Int32"   
headertext="ServerID" readonly="True" sortexpression="ServerID"   
uniquename="ServerID" Visible="False"></Telerik:GridBoundColumn>   
<Telerik:GridBoundColumn datafield="SystemName" headertext="SystemName"   
sortexpression="SystemName" uniquename="SystemName"></Telerik:GridBoundColumn>   
<Telerik:GridBoundColumn datafield="SerialNumber"   
headertext="SerialNumber" sortexpression="SerialNumber"   
uniquename="SerialNumber"></Telerik:GridBoundColumn>   
<Telerik:GridNumericColumn datafield="EnvironmentID"   
datatype="System.Int32" headertext="EnvironmentID"   
sortexpression="EnvironmentID" uniquename="EnvironmentID" AutoPostBackOnFilter="true"></Telerik:GridNumericColumn>   
<Telerik:GridBoundColumn datafield="EnvironmentName"   
headertext="EnvironmentName" sortexpression="EnvironmentName"   
uniquename="EnvironmentName"></Telerik:GridBoundColumn>   
</Columns>   
</MasterTableView>   
</telerik:RadGrid>   
 
<asp:SqlDataSource ID="SqlDataViewServerLookup" runat="server"   
ConnectionString="<%$ ConnectionStrings:CMDBConnectionString %>"   
SelectCommand="SELECT * FROM [ViewServerLookups]"></asp:SqlDataSource>  

And here's the stuff from the code behind:
protected void ServerRadGrid_PreRender(object sender, EventArgs e)  
        {  
            if (!Page.IsPostBack)  
            {  
                ServerRadGrid.MasterTableView.FilterExpression = "([EnvironmentID]!='4')";  
                GridColumn column = ServerRadGrid.MasterTableView.GetColumnSafe("EnvironmentID");  
                column.CurrentFilterFunction = GridKnownFunction.NotEqualTo;  
                ServerRadGrid.MasterTableView.Rebind();  
            }  
        } 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Oct 2009, 08:11 AM
Hello David,

Can you try replacing the filter expression as shown below and check if it helps:
c#:
if (!Page.IsPostBack) 
        { 
            ServerRadGrid.MasterTableView.FilterExpression = "([EnvironmentID] <> '4') "
            GridColumn column = ServerRadGrid.MasterTableView.GetColumnSafe("EnvironmentID"); 
            column.CurrentFilterFunction = GridKnownFunction.NotEqualTo;            
            ServerRadGrid.MasterTableView.Rebind(); 
        } 

Thanks
Princy.
0
David Kingston
Top achievements
Rank 2
answered on 20 Oct 2009, 01:37 PM
That worked.  I knew it had to be the expression.  Interesting as the basic filtering page shows != as a valid operator. I wish there was an easy way to get the filter expression that is used when you enter it manually so that there is less guessing on whether or not the one you're using works.
Tags
Grid
Asked by
David Kingston
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
David Kingston
Top achievements
Rank 2
Share this question
or