Filtering RadGrid will filled from DataTable

2 posts, 0 answers
  1. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 06 Oct 2011 Link to this post

    I have a screen with a radgrid that is filled using the NeedDataSource Event
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
               int count = 0;
               if (RadGrid1.MasterTableView.SortExpressions.Count > 0)
                   RadGrid1.DataSource = GetEntities(RadGrid1.PageSize, RadGrid1.MasterTableView.CurrentPageIndex * RadGrid1.PageSize, RadGrid1.MasterTableView.FilterExpression,
                      RadGrid1.MasterTableView.SortExpressions[0].FieldName + " " + RadGrid1.MasterTableView.SortExpressions[0].SortOrderAsString(), out count);
                   RadGrid1.DataSource = GetEntities(RadGrid1.PageSize, RadGrid1.MasterTableView.CurrentPageIndex * RadGrid1.PageSize, RadGrid1.MasterTableView.FilterExpression, "", out count);
               RadGrid1.MasterTableView.VirtualItemCount = count;
           private DataTable GetEntities(int maximumRows, int startRowIndex, string filterExpression, string sortExpression, out int count)
               ClientDataContext db = new ClientDataContext();
               var query = from g in db.GovtEntityLogs
                           select new
               //Set filter expresion
               if (!String.IsNullOrEmpty(filterExpression))
                   query = query.Where(String.Format(@"{0}", filterExpression));
               if (!String.IsNullOrEmpty(sortExpression))
                   query = query.OrderBy(sortExpression);
                   query = query.OrderBy("ClientName");
               //Set the total row count
               count = query.Count();
               var pagedData = query.Skip(startRowIndex).Take(maximumRows);
               DataTable dt = new DataTable();
               dt = pagedData.ToADOTable();
               return dt;

    This works fine as long as I have the page setting
    <%@ Page Title="" EnableViewState="false"

    but when I Filter from multilpe columns it only sorts the last column selected.  When I change the EnableViewState to TRUE, I get an error in the Filter in Dynamic.cs
    "No applicable indexer exists in type '<>f__AnonymousType50`12'"
    When I look at teh filter expression it shows

    "(Convert.ToString(it[\"ClientName\"]).ToUpper() = \"Capital Investment Advisory Services, LLC (CIAS)\".ToUpper())"

    Am I missing something?

  2. Iana Tsolova
    Iana Tsolova avatar
    3388 posts

    Posted 09 Oct 2011 Link to this post

    Hello Eric,

    When wit disabled ViewState try setting the grid DataSource to null in the ItemCommand event:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        if(e.CommandName == "Page" || e.CommandName == "Filter" || e.CommandName == "Sort")
            RadGrid1.DataSource = null;

    Also, see if setting EnableLinqExpressions to false makes any difference.

    Best wishes,
    Iana Tsolova
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. DevCraft R3 2016 release webinar banner
Back to Top