I've got a grid with data that can be sorted, paged and filtered by the end user. The grid data is tied to a declarative EntityDataSource and it works very well. I want to filter the data returned by the EntityDataSource so that the user only sees a subset of the records.
OK, so I can't use a declarative EDS and Filters on the grid at the same time as the Filters overwrite the 'Where' clause I put in the EDS. So I'm trying to move the EDS to code behind using the NeedDataSource event.
This is the problem I can see, it seems that the NeedDataSource event expects ALL data to be returned (already bound) which means I'll have lost all of my automatic paging and sorting on the server. I also can't see an example that uses the EDS like this (my code below encounters a NullException error).
My code:
The code above does not work, the code below (from the demo) looks like paging and sorting are done in the grid, not passed to the datasource which means the benefit of the EDS is lost (only fetching the rows needed etc).
Example from demo:
Questions;
1) Is there a good sample of using EDS in code behind?
2) Is there another way to accomplish this declaratively?
3) Will the EDS in the code behind always get all of the data and sort it in the grid or does it use the EDS properly?
Thanks in advance,
Ryan
OK, so I can't use a declarative EDS and Filters on the grid at the same time as the Filters overwrite the 'Where' clause I put in the EDS. So I'm trying to move the EDS to code behind using the NeedDataSource event.
This is the problem I can see, it seems that the NeedDataSource event expects ALL data to be returned (already bound) which means I'll have lost all of my automatic paging and sorting on the server. I also can't see an example that uses the EDS like this (my code below encounters a NullException error).
My code:
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
var Eds =
new
EntityDataSource();
Eds.DefaultContainerName =
"EntityDb"
;
Eds.ConnectionString =
"name=EntityDb"
;
Eds.EntitySetName =
"Meetings"
;
Eds.EnableDelete =
true
;
Eds.EnableInsert =
true
;
Eds.EnableUpdate =
true
;
Eds.AutoPage =
true
;
Eds.Include =
"Venue"
;
Eds.OrderBy =
"it.StartDate"
;
RadGrid1.DataSource = Eds;
}
The code above does not work, the code below (from the demo) looks like paging and sorting are done in the grid, not passed to the datasource which means the benefit of the EDS is lost (only fetching the rows needed etc).
Example from demo:
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
OleDbConnection conn =
new
OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
+ Server.MapPath(
"~/App_Data/Nwind.mdb"
));
OleDbDataAdapter adapter =
new
OleDbDataAdapter();
adapter.SelectCommand =
new
OleDbCommand(
"SELECT * FROM Customers"
, conn);
DataTable myDataTable =
new
DataTable();
conn.Open();
try
{
adapter.Fill(myDataTable);
}
finally
{
conn.Close();
}
RadGrid1.DataSource = myDataTable;
}
Questions;
1) Is there a good sample of using EDS in code behind?
2) Is there another way to accomplish this declaratively?
3) Will the EDS in the code behind always get all of the data and sort it in the grid or does it use the EDS properly?
Thanks in advance,
Ryan