In a grid view,
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound"
ShowFooter="True" AllowPaging="True" PageSize="5"
BackColor="#ffffff" BorderColor="AliceBlue"
BorderStyle="None" BorderWidth="1px"
CellPadding="3"
CellSpacing="2" FooterStyle-BackColor="#da821e"
FooterStyle-ForeColor="#ffffff"
RowStyle-BackColor="#003366"
RowStyle-ForeColor="#ffffff"
AlternatingRowStyle-BackColor="#da821e">
<columns>
<asp:boundfield datafield="ID" headertext="ID">
InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:boundfield datafield="Name" headertext="Name">
InsertVisible="False" ReadOnly="True"
SortExpression="Name" FooterText="Total"/>
<asp:templatefield headertext="Amount">
<itemtemplate>
<asp:label id="lblAmount" runat="server">
Text='<%# "$"+Eval("Amount").ToString()%>'>
</asp:label>
</itemtemplate>
<footertemplate>
<asp:label id="lblTotal" runat="server"></asp:label>
</footertemplate>
</asp:templatefield>
</asp:boundfield></asp:boundfield></columns>
<pagerstyle forecolor="#8C4510" horizontalalign="Center" />
<headerstyle backcolor="#da821e" font-bold="True">
ForeColor="White" />
</headerstyle></asp:gridview>
<asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Amount] FROM [Expenses]">
</asp:sqldatasource>
<pre lang="text">
in aspx page
public partial class _Default : System.Web.UI.Page
{
decimal grdTotal = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
.protected void GridView1_RowDataBound
(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal rowTotal = Convert.ToDecimal
(DataBinder.Eval(e.Row.DataItem, "Amount"));
grdTotal = grdTotal + rowTotal;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblTotal");
lbl.Text = grdTotal.ToString("c");
}
}
}