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

[Solved] Problem with filtering

2 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vo_one
Top achievements
Rank 1
vo_one asked on 28 Jul 2009, 05:06 PM
Hello Everybody

I'm using NeedDataSource event to populate grid with data. That's what grid tag looks like:

<telerik:RadGrid runat="server" ID="gridUsers" AutoGenerateColumns="false"  
        AllowPaging="true" AllowCustomPaging="true" 
        onneeddatasource="gridUsers_NeedDataSource" ShowStatusBar="true"  
        PageSize="25" onpageindexchanged="gridUsers_PageIndexChanged"  
        ondatabound="gridUsers_DataBound"
        <MasterTableView AllowFilteringByColumn="true"
            <PagerStyle Mode="Slider" /> 
            <Columns> 
                <telerik:GridTemplateColumn CurrentFilterFunction="StartsWith" ShowFilterIcon="false" AutoPostBackOnFilter="true" HeaderText="Username" SortExpression="Username"
                    <ItemTemplate> 
                        <href="<%#UrlHelpers.GetUserProfileUrl(Eval("UserID")) %>"
                            <%#Eval("Username") %> 
                        </a> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn AllowFiltering="false" HeaderText="First name" DataField="FirstName"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn AllowFiltering="false" HeaderText="Last name" DataField="LastName"
                </telerik:GridBoundColumn> 
            </Columns>     
        </MasterTableView> 
    </telerik:RadGrid>  

That's a NeedDataSource event handler which I use:

protected void gridUsers_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    { 
        using (DataClassesDataContext db = new DataClassesDataContext())  
        { 
            var query = from c in db.Users  
                        select  
                        new  
                        { 
                            c.FirstName,   
                            c.LastName, 
                            c.Username, 
                            c.UserID 
                        }; 
            gridUsers.MasterTableView.VirtualItemCount = query.Count(); 
            gridUsers.DataSource = query.Skip(gridUsers.CurrentPageIndex*gridUsers.PageSize).Take(gridUsers.PageSize).ToList(); 
        } 
    } 
 
I feel confused, because nearly all live demos that illustrate filtering stuff use SqlDataSource for data binding, not NeedDataSource handling. Every time I try to filter the grid by username I get an error which says "Expression expected". Could anybody give me a tip that would help me to solve the issue without changing the way data binding is done?

Thanks in advance!  

2 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 29 Jul 2009, 08:19 AM
Hi,

Please set EnableLinqExpressions to false to avoid this.
For more information about FilterExpression I suggest you review the following articles:
http://www.telerik.com/help/aspnet-ajax/telerik.web.ui-telerik.web.ui.gridtableview-filterexpression.html
http://www.telerik.com/help/aspnet-ajax/grdoperatewithfilterexpression.html

Sincerely yours,
Pavlina
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
vo_one
Top achievements
Rank 1
answered on 29 Jul 2009, 11:37 AM
Thanks  for the reply. I've already found out what was wrong. I had to initialize DataField property of GridTemplate column. Exception wasn't thrown anymore after I did that. 
Tags
Grid
Asked by
vo_one
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
vo_one
Top achievements
Rank 1
Share this question
or