Telerik Radgrid Column Calculation
Telerik Radgrid Column Calculation
In Radgrid we can so any type of calculation very easily and
swiftly .
In this we can perform mathematical operation like addition,subtraction,multiplication
and dividedation on rows and columns .
In this article I am did three function.
1) Counting its total rows
2) Sum of its column and displaying it in footer
3) Multiplication on Column 2 and 3 and displaying its
result in column 5.
Step 1: Design web Form .aspx page
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" Width="50%" PagerStyle-AlwaysVisible="true" ShowFooter="true"
GridLines="None" AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource">
<HeaderStyle HorizontalAlign="Left" />
<MasterTableView DataKeyNames="name" AutoGenerateColumns="false">
<NoRecordsTemplate>No records found.</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn Aggregate="Count" DataField="Name" HeaderText="Name"
FooterText="Total Count:
">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn Aggregate="Sum" DataField="Amount" HeaderText="Amount" DataType="System.Int32"
FooterText="Total Amount:
">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="UnitCount" DataField="UnitCount" />
<telerik:GridBoundColumn HeaderText="Phone" DataField="Phone" />
<telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double"
DataFields="Amount, UnitCount" Expression="{0}*{1}" FooterText="Total : "
Aggregate="Sum">
</telerik:GridCalculatedColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
Step 2: Logic on .Cs page
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Amount",typeof (Int32) );
dt.Columns.Add("Phone");
dt.Columns.Add("UnitCount", typeof(Int32));
dt.Rows.Add("Kandy", "12", "8802***2564","2");
dt.Rows.Add("Sam", "25", "545502*2544","4");
dt.Rows.Add("Izhar", "32", "95802*2452","4");
dt.Rows.Add("Vineet", "10", "88022564***","6");
RadGrid1.DataSource = dt;
}
Comments
Post a Comment