How to create a Footer in Gridview to display Total salaries
Hi Friends,In this article i would like to explain how to create a footer in gridview for display total salaries
First,open the Default.aspx source page where we insert the gridview
Next,Just copy the following code from which you would like to display the Footer
Finally,Execute the code...That's it...:D
First,open the Default.aspx source page where we insert the gridview
Next,Just copy the following code from which you would like to display the Footer
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="5" DataKeyNames="EmpID" ForeColor="#333333" GridLines="None" CellSpacing="5" >
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Salary" >
<ItemTemplate>
<asp:Label ID="lbl_sal" runat="server" Text='<%# Bind("Salary")%>'>>
</asp:Label></ItemTemplate>
<EditItemTemplate>
<asp:Label ID="sal1" runat="server" Text='<%# Bind("Salary") %>'>
</asp:Label>
</EditItemTemplate>
<FooterTemplate>
<%# gettotal()%></FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Next,come to the code page that is Default.aspx.cs and copy the following codepublic int gettotal()
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["SAMPLE_2"].ToString());
con.Open();
SqlCommand com = new SqlCommand("SELECT SUM(Salary) FROM Employee_Details", con);
int totalsal = Convert.ToInt32(com.ExecuteScalar());
con.Close();
return totalsal;
}
Finally,Execute the code...That's it...:D
Labels: .Net Tutorials, Aspnet, C#, CSharp, Gridview, Tanisha
3 Comments:
thanks a lot
its working thankyou sooooooooooooooooooo much
its working thankyou sooooooooooooooooooo much
Post a Comment
Subscribe to Post Comments [Atom]
<< Home