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

EnableLinqExpressions throwing exception

5 Answers 608 Views
Grid
This is a migrated thread and some comments may be shown as answers.
brad
Top achievements
Rank 1
brad asked on 19 Feb 2009, 07:33 PM
Hello,

Im having an issue with the RadGrid and allowing Column Filtering. Basicly what has happened is that we had a grid. we had filtering on it and the filtering worked for awhile. we updated our controls to .1314, afterwards filtering started throwing an exception "no property or field 'username' exist in object". from my understanding this was an issue nearly a year ago and hotfix was applied.

to make things worse is that through searching the forums i found out setting the EnableLinqExpressions = false will allow the filtering to happen without throwing an exception, but when i set that property to false, the paging on the grid no longer works. the telerik pager, defaults to page 1, but when you click page 3, the pager is saying page 3 but the grid itself is still displaying records from page 1.

for awhile i believed it to be an ajax problem and i disabled all the ajax on the page and the problem still persist.

so, in a nutshell, if EnableLinqExpression is not set to False, we cannot use the Filtering provided in the control, if we do set EnableLineExpression to False, the pager does not work appropriately.

any help at all would be appreciated.

public partial class esAdmin_test : System.Web.UI.Page 
    public RadPane gridPane; 
    private UserBE.SelectionTypes _selectType = 0; 
    //public RadAjaxManager RadAjaxManager1; 
    //public RadAjaxLoadingPanel RadAjaxLoadingPanel1; 
 
    public UserBE.SelectionTypes SelectType 
    { 
        set { _selectType = value; } 
        get { return _selectType; } 
    } 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        RadSplitter mpSplitter = (RadSplitter)Master.FindControl("NestedSplitter"); 
        if (mpSplitter != null
        { 
            ArrayList panes = mpSplitter.GetPanes(); 
            RadPane pane = (RadPane)panes[2]; 
            gridPane = (RadPane)panes[1]; 
            int paneIndex = pane.Index; 
            mpSplitter.Items.RemoveAt(paneIndex); 
        } 
 
        //RadAjaxManager1 = (RadAjaxManager)Master.FindControl("RadAjaxManager1"); 
        //RadAjaxLoadingPanel1 = (RadAjaxLoadingPanel)Master.FindControl("RadAjaxLoadingPanel1"); 
        //RadAjaxManager.GetCurrent(this.Page).AjaxSettings.AddAjaxSetting(this.RadAjaxManager1, this.RadGrid1, RadAjaxLoadingPanel1); 
        //RadAjaxManager.GetCurrent(this.Page).AjaxSettings.AddAjaxSetting(this.RadGrid1, this.RadGrid1, RadAjaxLoadingPanel1); 
       
    } 
 
    protected void RadGrid1_OnNeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    { 
        SessionManager _session = new SessionManager(); 
 
        ObjectContainerDataSource _datasource = new ObjectContainerDataSource(); 
        _datasource.DataObjectTypeName = "Peminic.Business.BusinessEntities.UserBE"
        _datasource.DataSource = UserBE.GetBySelectionType(UserBE.Context.AreoOfResponsibility, _session.UserID, SelectType); 
 
        RadGrid1.DataSource = _datasource; 
    } 
 
    protected void rdoSelectUser_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        SelectType = (UserBE.SelectionTypes)Convert.ToInt32(rdoSelectUser.SelectedValue); 
        RadGrid1.CurrentPageIndex = 0; 
        RadGrid1.Rebind(); 
    } 
 
    protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument) 
    { 
        //RadGrid1.Rebind(); 
 
        base.RaisePostBackEvent(sourceControl, eventArgument); 
 
        if (sourceControl is RadAjaxManager) 
        { 
            if (eventArgument == "Rebind"
            { 
                RadGrid1.MasterTableView.SortExpressions.Clear(); 
                RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
                RadGrid1.Rebind(); 
            } 
 
            if (eventArgument == "ChangePageSize"
            { 
                Session["itemsCount"] = this.RadGrid1.Items.Count; 
 
                //Depending on the paticular scenario this value may vary. 
                int rows = (Int32.Parse(this.gridPane.Height.Value.ToString()) - 20) / 32; 
                if (rows >= 1) 
                { 
                    RadGrid1.PageSize = rows; 
 
                    // Check whether the CurrentPageIndex is correct. 
                    if (Session["itemsCount"] != null
                    { 
                        int itemsCount = (int)Session["itemsCount"]; 
                        int pageCount = (int)Math.Ceiling(((double)itemsCount / rows)); 
                        if (RadGrid1.MasterTableView.CurrentPageIndex > pageCount - 1) 
                        { 
                            RadGrid1.MasterTableView.CurrentPageIndex = pageCount - 1; 
                        } 
                    } 
                    RadGrid1.Rebind(); 
                } 
            } 
        } 
    } 

<asp:Content ID="Content3" runat="server" ContentPlaceHolderID="ContentPlaceHolderRuleNav"
    <div class="qsfexHeaderMain">Test Group Filter</div> 
    <asp:RadioButtonList ID="rdoSelectUser" runat="server" AutoPostBack="True"  
        Font-Names="Verdana"   
        style="margin-right: 61px"  
        onselectedindexchanged="rdoSelectUser_SelectedIndexChanged"
        <asp:ListItem Selected="True" Value="0">All</asp:ListItem> 
        <asp:ListItem Value="1">Active</asp:ListItem> 
        <asp:ListItem Value="2">Disabled</asp:ListItem> 
        <asp:ListItem Value="3">Last 3 Months</asp:ListItem>          
        <asp:ListItem Value="4">Locked Out</asp:ListItem> 
</asp:RadioButtonList>                            
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderMain" Runat="Server"
        <asp:Panel ID="Panel" runat="server"
            <telerik:RadGrid ID="RadGrid1" runat="server" PageSize="10" 
                 AllowPaging="True" GridLines="None" AutoGenerateColumns="False"  
                 AllowFilteringByColumn="true" EnableLinqExpressions="false" 
                 OnNeedDataSource="RadGrid1_OnNeedDataSource"
                <PagerStyle Mode="NextPrevNumericAndAdvanced"
                </PagerStyle> 
                <MasterTableView DataKeyNames="UserID" AllowMultiColumnSorting="True"
                    <GroupByExpressions> 
                    </GroupByExpressions> 
                    <Columns> 
                        <telerik:GridBoundColumn DataField="UserID" Visible="false" SortExpression="UserID"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="LastName" SortExpression="LastName" HeaderText="Last Name"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="FirstName" SortExpression="FirstName" HeaderText="First Name"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Username" SortExpression="Username" HeaderText="User ID"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Email" SortExpression="Email" HeaderText="Email"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Status" SortExpression="Status" HeaderText="Status"
                        </telerik:GridBoundColumn> 
                    </Columns> 
                </MasterTableView> 
                <ClientSettings > 
                    <Selecting AllowRowSelect="True"></Selecting> 
                    <Scrolling AllowScroll="True"></Scrolling> 
                    <ClientMessages /> 
                </ClientSettings> 
            </telerik:RadGrid> 
        </asp:Panel> 
</asp:Content> 
 

5 Answers, 1 is accepted

Sort by
0
brad
Top achievements
Rank 1
answered on 20 Feb 2009, 03:05 PM
To update things further with more information....


we also built a custom pager which we would like to use with all of our grids. on the orginal problem with the default pager, i figured a work around using the OnPageIndexChanged event setting the EnableLinqExpressions to true, then creating a Page_PreRender method and setting the EnableLinqExpressions back to False. once i do this, i am able to successfully Filter, and im also able to effectively changes pages.

however, the problem them becomes the pager not refreshing. if there are 50 items in the grid and i do a filter so there is only 1 item, the pager still displays a count total of 50 items, it also still shows all the page numbers up to 6, and theres only 1 item in the grid so only page 1 should be displayed.

the telerik default pager is not refreshing.

so i tried it with our custom pager and the result was the exact same.

im not sure why this property is creating so much trouble.
0
Georgi Krustev
Telerik team
answered on 23 Feb 2009, 06:01 PM
Hello Brad,

With the .NET 3.5 build of RadGrid for ASP.NET AJAX and LINQ filter expressions enabled (EnableLinqExpressions = true), the filter expressions set for the grid either internally by its filtering mechanism or manually in code should conform to the LINQ expression syntax instead of the old T-SQL syntax. Only thus they will be evaluated properly by the control. Here you can find further information on this matter.

Here is a code snippet which showing how to apply proper LINQ expression syntax:
public void Page_Load(object sender, EventArgs e) 
       { 
           if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1) 
           { 
               RadGrid1.MasterTableView.FilterExpression = @"it[""ReportsTo""] = Convert.DBNull"
           } 
           else 
           { 
               RadGrid1.MasterTableView.FilterExpression = "ReportsTo IS NULL"
           } 
       } 

This code snippet is quoted from this online demo.

Kind regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
brad
Top achievements
Rank 1
answered on 24 Feb 2009, 07:53 PM
  if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1) 
                { 
                    grdUsers.MasterTableView.FilterExpression = @"it[""FirstName""] = Convert.DBNull"
                } 
                else 
                { 
                    grdUsers.MasterTableView.FilterExpression = "FirstName IS NULL"
                } 

I use that code in the Page_Load as you suggested, however it throws an No applicable indexer exists in type 'Object'  exception.

the rest of the code seems to build correctly except for the line

@"it[""FirstName""] = Convert.DBNull";  

im not quit sure what is wrong with this, i have searched around and apparently im not the only person with this problem when using a telerik control.

here is the stacktrace -

Server Error in '/WebAgent' Application.

No applicable indexer exists in type 'Object'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Telerik.Web.UI.ParseException: No applicable indexer exists in type 'Object'

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ParseException: No applicable indexer exists in type 'Object']
   Telerik.Web.UI.ExpressionParser.ParseElementAccess(Expression expr) +779
   Telerik.Web.UI.ExpressionParser.ParsePrimary() +109
   Telerik.Web.UI.ExpressionParser.ParseUnary() +365
   Telerik.Web.UI.ExpressionParser.ParseMultiplicative() +54
   Telerik.Web.UI.ExpressionParser.ParseAdditive() +54
   Telerik.Web.UI.ExpressionParser.ParseComparison() +57
   Telerik.Web.UI.ExpressionParser.ParseLogicalAnd() +49
   Telerik.Web.UI.ExpressionParser.ParseLogicalOr() +49
   Telerik.Web.UI.ExpressionParser.ParseExpression() +60
   Telerik.Web.UI.ExpressionParser.Parse(Type resultType) +58
   Telerik.Web.UI.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) +81
   Telerik.Web.UI.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) +114
   Telerik.Web.UI.GridDynamicQueryable.Where(IQueryable source, String predicate, Object[] values) +187
   Telerik.Web.UI.GridDataTableFromEnumerable.FillData35() +3683
   Telerik.Web.UI.GridDataTableFromEnumerable.FillData() +990
   Telerik.Web.UI.GridResolveEnumerable.Initialize() +55
   Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized() +40
   Telerik.Web.UI.GridResolveEnumerable.get_DataTable() +31
   Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +221
   Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +155
   Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +478
   Telerik.Web.UI.GridTableView.get_ResolvedDataSource() +219
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +73
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   Telerik.Web.UI.GridTableView.PerformSelect() +28
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +365
   Telerik.Web.UI.RadGrid.DataBind() +165
   Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +3849
   Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +177
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053




0
Georgi Krustev
Telerik team
answered on 27 Feb 2009, 02:39 PM
Hello Brad,

I noticed that you bind the grid with custom object collection. In this case you must check when the required object property is null. In the code snippet from your last post, the "it" is the single item from the data source. In other words if the grid is bound with DataTable, the "it" item will be the DataTable.DataRowDefaultView[0]. And as you know to get a current item, you can use it["ColumnName"] indexer property to get it. When you bind the grid with custom object collection and if Indexer property is not implemented, you need to use "it.PropertyName" to get the corresponding value and to check it.

Here is a code snippet explaining what I mean:
  if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)  
                {  
                    grdUsers.MasterTableView.FilterExpression = @"it.FirstName = Convert.DBNull";  
                }  
                else  
                {  
                    grdUsers.MasterTableView.FilterExpression = "FirstName IS NULL";  
                }  

Please give it a try and let me know how it goes.

Regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Dany
Top achievements
Rank 1
answered on 18 Aug 2010, 04:14 PM
Hi guys, just to let you know i spend few hours to find a solution when the exception "Specified argument was out of the range of valid values " happen on the list_SelectedIndexChanged    filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName));} command.

I don't know if this will help the community but i finally find that when you duplicate the same field (like my exemple) the exception occru,  i juste remove the second one (<telerik:GridBoundColumn DataField="LogType"  />) and everything run properly

<

 

Columns>

 


    <

 

custom:MyCustomFilteringColumn DataField="LogType" HeaderText="Type">
    <telerik:GridBoundColumn DataField="LogType"  />

 

</

 

Columns>


Regards

DAny

 

Tags
Grid
Asked by
brad
Top achievements
Rank 1
Answers by
brad
Top achievements
Rank 1
Georgi Krustev
Telerik team
Dany
Top achievements
Rank 1
Share this question
or