Hi Gopal_nivas
it's very easy going on you get total in Footer Tempalte in A Gridview Like This
in a grid view
<asp:GridView ID="GridView1" runat="server"
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>
</Columns>
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#da821e" Font-Bold="True"
ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Amount] FROM [Expenses]">
</asp:SqlDataSource>
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");
}
}
}
it's a use full for you . .
Best Regard's
Prabhakar
Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator