Thursday, February 3, 2011

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


<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 code
public 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
developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , , ,

3 Comments:

At April 25, 2011 at 7:54 PM , Anonymous Anonymous said...

thanks a lot

 
At April 25, 2011 at 7:54 PM , Anonymous Anonymous said...

its working thankyou sooooooooooooooooooo much

 
At June 28, 2011 at 10:16 AM , Anonymous Anonymous said...

its working thankyou sooooooooooooooooooo much

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home