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

Get Filtered Data from Grid via Entity Framework

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 03 Mar 2015, 06:13 AM
Good afternoon - using the Entity Framework / an Entity Data Source, I need to get the data the user has filtered from the Grid. What's the easiest way? 

It seems difficult to iterate through the entire paged data-set getting ID's and then re-fetching all the rows based on the Primary Key/ID. 

I've found a "double rebind" hack works quite well - though not sure on performance yet - but I'd be interested to hear the best options:

        private bool StoreInLocalVariable;
        private Collection<CustomerData> CustomerData;

protected
void btnGetData_Click(object sender, EventArgs e)
{
   // Rebind grid without paging to get full data-set
                StoreInLocalVariable = true;        
            rgCustomerBalance.AllowPaging = false;
            rgCustomerBalance.Rebind();
            var result = CustomerData;
 
// Restore grid back to normal (i.e. with paging)
            StoreInLocalVariable = false;
            rgCustomerBalance.AllowPaging = true;
            rgCustomerBalance.Rebind();
 
           // Do something with Result
}
 
        // Entity Data Source Selected
        protected void edsCustomerData_Selected(object sender, EntityDataSourceSelectedEventArgs e)
        {
            if (StoreInLocalVariable)
            {
                CustomerData = new Collection<CustomerData>(e.Results.Cast<CustomerData>().ToList());
            }
        }

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 05 Mar 2015, 03:36 PM
Hi,

If you need to get the entire data set, the "double rebind" approach that you are currently using is the only available one.

However, if you have something different in mind, please elaborate on your exact requirement.


Best Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
 
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or