Hello Zhihao,
You can find many examples of working projects that demonstrate how to integrate
OpenAccess and some other popular technologies in
OpenAccess SDK. Yout can download the SDK from
http://www.telerik.com/products/orm/features/sdk.aspx.
After installing it you can take a look at
ASP.NET -> Sofia Car Rental ASP.NET Ajax example.
There you can find
AvailableCarsGrid.ascx under
SofiaCarRenta.Web/Views.
The situation there is very similar to the one you are trying to implement: each
Car entity has a
Category.
The grid in the example shows that category and allows users to group and sort the whole grid by this column.
The code to bind the grid in the
.ascx file is pretty simple (I have omitted the unnecessary details):
01.
<
telerik:RadGrid
ID
=
"rgCars"
runat
=
"server"
ShowGroupPanel
=
"True"
02.
AllowPaging
=
"true"
DataSourceID
=
"ldsCars"
AllowSorting
=
"true"
>
03.
<
MasterTableView
AutoGenerateColumns
=
"false"
OverrideDataSourceControlSorting
=
"true"
04.
ClientDataKeyNames
=
"CarID, Make"
>
05.
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
ShowPagerText
=
"false"
PageSizeLabelText
=
""
/>
06.
<
GroupByExpressions
>
07.
<
telerik:GridGroupByExpression
>
08.
<
SelectFields
>
09.
<
telerik:GridGroupByField
FieldAlias
=
"Category"
FieldName
=
"Category.CategoryName"
FormatString
=
"{0:D}"
>
10.
</
telerik:GridGroupByField
>
11.
</
SelectFields
>
12.
<
GroupByFields
>
13.
<
telerik:GridGroupByField
FieldName
=
"Category.CategoryName"
SortOrder
=
"Descending"
></
telerik:GridGroupByField
>
14.
</
GroupByFields
>
15.
</
telerik:GridGroupByExpression
>
16.
</
GroupByExpressions
>
17.
<
Columns
>
18.
<
telerik:GridBoundColumn
DataField
=
"CarID"
UniqueName
=
"CarID"
Visible
=
"false"
>
19.
</
telerik:GridBoundColumn
>
20.
<
telerik:GridBoundColumn
DataField
=
"Category.CategoryName"
UniqueName
=
"Category"
HeaderText
=
"Category"
>
21.
</
telerik:GridBoundColumn
>
22.
<
telerik:GridBoundColumn
DataField
=
"Make"
UniqueName
=
"Make"
HeaderText
=
"Make"
>
23.
</
telerik:GridBoundColumn
>
24.
<
telerik:GridBoundColumn
DataField
=
"Model"
UniqueName
=
"Model"
HeaderText
=
"Model"
>
25.
</
telerik:GridBoundColumn
>
26.
</
Columns
>
27.
</
MasterTableView
>
28.
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
29.
<
Selecting
AllowRowSelect
=
"true"
/>
30.
<
ClientEvents
OnRowSelected
=
"RowSelected"
/>
31.
</
ClientSettings
>
32.
</
telerik:RadGrid
>
The column binding is done on
line 20.
Lines between
lines 6 and 16 define how to group the items in the grid using again the
Category column.
Grid's
DataSource is set to an instance of
OpenAccessLinqDataSource (
DataSourceID
=
"ldsCars"
) on line 2.
The
DataSource itself is defined using the following code:
Later the data source is populate through a
Web Service call. In the server side code you can find how the data is loaded. Look at
SofiaCarRental.Model/Services/CarsService.cs:
As you can see from the code above we are querying using
LINQ extension methods for data and then returning it as a
List<Car>.
I believe the hardest link to implement is the creation of the
OpenAccessLinqDataSource object. You can find more information at
http://www.telerik.com/help/openaccess-orm/developer-guide-oalinqdatasource-overview.html.
I believe you can translate the example for your scenario and use the same technique to bind FunctionFields and Functions to a grid.
I hope that this will clear any issues you have faced and will enable you to complete successfully your project using
OpenAccess.
Kind regards,
Viktor Zhivkov
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!