Telerik Radgrid Aggregate function for calucalation
Telerik Radgrid Aggregate function for calucalation
Radgrid provide 10 type of predefined aggregate function for
simplifying calculation.
Some of them are using in this article.
Step 1:Design web from .aspx page
<div>
<asp:ScriptManager ID="ss" runat="server"></asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" PageSize="8" Width="50%" PagerStyle-AlwaysVisible="true" ShowFooter="true"
GridLines="None" AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource">
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
<HeaderStyle HorizontalAlign="Left" />
<MasterTableView DataKeyNames="name" AutoGenerateColumns="false">
<NoRecordsTemplate>No records found.</NoRecordsTemplate>
<Columns>
<telerik:GridNumericColumn Aggregate="Count" DataField="Name" HeaderText="Name"
SortExpression="Name" UniqueName="Name" HeaderStyle-Width="80px">
</telerik:GridNumericColumn>
<telerik:GridNumericColumn Aggregate="Avg" DataField="Amount" HeaderText="Amount"
SortExpression="Amount" UniqueName="Amount" DataFormatString="{0:C}" HeaderStyle-Width="100px">
</telerik:GridNumericColumn>
<telerik:GridNumericColumn Aggregate="Sum" DataField="abc" HeaderText="abc"
SortExpression="abc" UniqueName="abc" HeaderStyle-Width="90px"
FilterControlWidth="40px">
</telerik:GridNumericColumn>
<telerik:GridNumericColumn Aggregate="Max" DataField="XYZ" HeaderText="XYZ"
SortExpression="XYZ" UniqueName="XYZ" HeaderStyle-Width="120px">
</telerik:GridNumericColumn>
<telerik:GridNumericColumn Aggregate="CountDistinct" DataField="KKK" HeaderText="KKK"
SortExpression="KKK" UniqueName="KKK"
HeaderStyle-Width="100px">
</telerik:GridNumericColumn>
</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("abc", typeof(Int32));
dt.Columns.Add("XYZ", typeof(Int32));
dt.Columns.Add("KKK", typeof(Int32));
dt.Rows.Add("Kandy", "12", "23", "33", "44");
dt.Rows.Add("Sam", "25", "12", "67", "77");
dt.Rows.Add("Izhar", "32", "09", "9", "8");
dt.Rows.Add("Vineet", "10", "89", "2", "3");
dt.Rows.Add("Kandy", "12", "23", "33", "44");
dt.Rows.Add("Sam", "25", "12", "67", "77");
dt.Rows.Add("Izhar", "32", "09", "9", "8");
dt.Rows.Add("Vineet", "10", "89", "2", "3");
RadGrid1.DataSource = dt;
}
Comments
Post a Comment