1 ss 12121 2 gg 23234 3 dd 34342 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" ShowFooter="True" AllowPaging="True" PageSize="5" CellPadding="4" ForeColor="#333333" GridLines="None" Width="451px" > <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <Columns> <asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="ID"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField FooterText="Total" HeaderText="Name" InsertVisible="False" SortExpression="Name"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Name") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Amount"> <ItemTemplate> <asp:Label ID="lblAmount" runat="server" Text='<%# "$"+Eval("Salary").ToString()%>'> </asp:Label> </ItemTemplate> <FooterTemplate> <asp:Label ID="lblTotal" runat="server"></asp:Label> </FooterTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#999999" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbRecruitmentConnectionString %>" SelectCommand="SELECT * FROM [EmpDetails]"> </asp:SqlDataSource> </div> </form> </body> </html> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class GrandTotalGrid : System.Web.UI.Page { decimal GrandTotal = 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, "salary")); GrandTotal = GrandTotal + rowTotal; } if (e.Row.RowType == DataControlRowType.Footer) { Label lbl = (Label)e.Row.FindControl("lblTotal"); lbl.Text = GrandTotal.ToString("c"); } } }
Thanks, Sanjay
Rathnayake
Join Hands Change lives Thanks & Regards Straight Edge Society
Login to post response