Hi dear friends!
Do you have a sample of asp.net webforms page populating a radgrid with entity framework objects in code behind. Example:
Do you have a sample of asp.net webforms page populating a radgrid with entity framework objects in code behind. Example:
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ClientsContext db = new ClientsContext(); var query = from b in db.Clients orderby b.LastName select new { Client = b.ClientId, First = b.FirstName, Last = b.LastName, County = b.CountyName, City = b.City }; GridView1.DataSource = query.ToList().Take(100); } } }
Your support will be greatly appreciated.
G
8 Answers, 1 is accepted
0
Hello Gonzalo,
I believe the following demo will give you a good starting point:
Best regards,
Daniel
the Telerik team
I believe the following demo will give you a good starting point:
Best regards,
Daniel
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.
0

Gonzalo
Top achievements
Rank 2
answered on 12 Sep 2012, 03:57 PM
Thanks Daniel. I will check this out.
0

Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 06 Feb 2015, 10:07 AM
Hi Daniel,
I believe there is an error in the C# code listed in your link, it shows:
But that gives errors, should it not be:
​
I believe there is an error in the C# code listed in your link, it shows:
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
var result = from r in DbContext.Products
select r;
RadGrid1.DataSource = result;
}
But that gives errors, should it not be:
protected
void
RadGrid1_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
var result = from r
in
DbContext.Products
select r;
RadGrid1.DataSource = result.toList();
}
​
0
Hi Al,
Know that this is the exact code which is used for creating the demo. I am not sure why the code throws an error on your side without replicating the issue locally. Could you please provide your an image of the exception that you have received and also your code declaration?
Regards,
Kostadin
Telerik
Know that this is the exact code which is used for creating the demo. I am not sure why the code throws an error on your side without replicating the issue locally. Could you please provide your an image of the exception that you have received and also your code declaration?
Regards,
Kostadin
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.
0

Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 11 Feb 2015, 08:33 AM
Hi Kostadin,
Please see the attached pic and code below.
​
Please see the attached pic and code below.
<
telerik:RadGrid
ID
=
"grdMain"
runat
=
"server"
AllowFilteringByColumn
=
"True"
AllowSorting
=
"True"
AutoGenerateDeleteColumn
=
"false"
AutoGenerateEditColumn
=
"false"
ShowGroupPanel
=
"True"
OnNeedDataSource
=
"grdMain_NeedDataSource"
OnPreRender
=
"grdMain_PreRender"
OnItemDataBound
=
"grdMain_ItemDataBound"
OnDeleteCommand
=
"grdMain_DeleteCommand"
AutoGenerateColumns
=
"true"
>
<
ClientSettings
AllowDragToGroup
=
"True"
>
<
ClientEvents
OnCommand
=
"grdMain_OnCommand"
/>
</
ClientSettings
>
<
MasterTableView
CommandItemDisplay
=
"Top"
EditMode
=
"PopUp"
>
<
RowIndicatorColumn
Visible
=
"False"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Created
=
"True"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridButtonColumn
CommandName
=
"Edit"
UniqueName
=
"Edit"
Text
=
"Edit"
ItemStyle-Width
=
"30px"
></
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
UniqueName
=
"Delete"
Text
=
"Delete"
ConfirmDialogType
=
"RadWindow"
ConfirmText
=
"Continue to delete?"
ItemStyle-Width
=
"30px"
></
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Groups"
UniqueName
=
"Groups"
Text
=
"Groups"
ItemStyle-Width
=
"30px"
></
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Rights"
UniqueName
=
"Rights"
Text
=
"Rights"
ItemStyle-Width
=
"30px"
></
telerik:GridButtonColumn
>
<
telerik:GridButtonColumn
CommandName
=
"AD_Paths"
UniqueName
=
"AD_Paths"
Text
=
"AD_Paths"
ItemStyle-Width
=
"60px"
></
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
​
0
Hello Al,
Could you please provide your code behind since I am still not able to replicate the issue that you are facing? Additionally which version of RadControls you are using?
Regards,
Kostadin
Telerik
Could you please provide your code behind since I am still not able to replicate the issue that you are facing? Additionally which version of RadControls you are using?
Regards,
Kostadin
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.
0

Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 16 Feb 2015, 08:03 AM
Hi Kostadin,
I did post my code-behind previously, nothing fancy there. In NeedDataSource I am using :
If I don't use add ToList() then I get the error. I am using version 2014.3.1209.45
I did post my code-behind previously, nothing fancy there. In NeedDataSource I am using :
var result = from r
in
DbContext.Products
select r;
RadGrid1.DataSource = result.ToList();
If I don't use add ToList() then I get the error. I am using version 2014.3.1209.45
0
Hello Al,
I isolate the example from the demos in a small runnable sample. As you can see there is no need to call ToList of the result. Could you please verify that you are using exactly the same entity model? If you are using a different one you might return a different type of data that requires to call toList as the exception notes.
Regards,
Kostadin
Telerik
I isolate the example from the demos in a small runnable sample. As you can see there is no need to call ToList of the result. Could you please verify that you are using exactly the same entity model? If you are using a different one you might return a different type of data that requires to call toList as the exception notes.
Regards,
Kostadin
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.