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

Using a GridCalculatedColumn with GridTemplateColumns

1 Answer 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samir Vaidya
Top achievements
Rank 1
Samir Vaidya asked on 23 Apr 2011, 04:00 AM
I would like to use a GridCalculatedColumn in conjunction with GridTemplateColumns.  However, all of the samples on the Telerik Demo site utilize GridBoundColumns in conjunction with GridCalculatedColumns.  I do not believe that I will be able to use a GridBoundColumn since I am binding to a collection of objects like so:

List<SelectedCourse> lstSelectedCourses = this.SelectedCourses;
 
            //Bind the GridView schedule
            gvSchedule.DataSource = lstSelectedCourses;
            gvSchedule.DataBind();

When I display the columns in the GridView, I use the following syntax:

<columns>
                        <telerik:gridtemplatecolumn>
                            <itemtemplate>
                                <asp:hiddenfield id="hfCourseID" value='<%#Eval("CourseID") %>' runat="server" />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Category">
                            <itemtemplate>
                                <asp:label id="lblCategory" runat="server" text='<%#Eval("Category") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Subject">
                            <itemtemplate>
                                <asp:label id="lblSubject" runat="server" text='<%#Eval("Subject") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Days">
                            <itemtemplate>
                                <asp:label id="lblDays" runat="server" text='<%#Eval("Days") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Start Time">
                            <itemtemplate>
                                <asp:label id="lblStartTime" runat="server" text='<%#Eval("StartTime") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="End Time">
                            <itemtemplate>
                                <asp:label id="lblEndTime" runat="server" text='<%#Eval("EndTime") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Term">
                            <itemtemplate>
                                <asp:label id="lblTerm" runat="server" text='<%#Eval("Term") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Length (Weeks)">
                            <itemtemplate>
                                <asp:label id="lblCourseLength" runat="server" text='<%#Eval("CourseLength") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Location">
                            <itemtemplate>
                                <asp:label id="lblLocation" runat="server" text='<%#Eval("Location") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>
                        <telerik:gridtemplatecolumn headertext="Cost">
                            <itemtemplate>
                                <asp:label id="lblCourseCost" runat="server" text='<%#Eval("Cost", "{0:C}") %>' />
                            </itemtemplate>
                        </telerik:gridtemplatecolumn>                       
                    </columns>

Is there a way to utilize the GridCalculatedColumn to sum up the value in the GridTemplateColumn for Cost?

Thanks. 

1 Answer, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 26 Apr 2011, 09:53 AM
Hi Samir,

There is no limitation or requirement which combination of columns you should use in a RadGrid. Furthermore, in your case there is no problem to use GridBoundColumn instead of GridTemplateColumn.
Furthermore, you can have aggregates for all column types. Thus the aggregated value for all records in a column will be displayed in the grid footer. You can find more information about RadGrid footer aggregates in the below resources:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/aggregates/defaultcs.aspx
http://tv.telerik.com/watch/aspnet/radgrid/telerik-trainer-radgrid-aggregate-column

On the other hand, the GridCalculatedColumn is useful when you need to display a calculated value in each row based on two or more data fields. Refer to the below demos for more details:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/calculatedcolumns/defaultcs.aspx

I hope this helps.

Best wishes,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Samir Vaidya
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or