Hi indradeo,
Refer below code.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="auto-style11" Height="138px" Width="99.7%" ShowFooter="true">
<Columns>
<asp:BoundField DataField="DEPARTMENT" HeaderText="DEPARTMENT" />
<asp:TemplateField HeaderText="Deviation">
<ItemTemplate>
<asp:LinkButton ID="Deviation" Text='<%# Eval("Deviation") %>' runat="server" CommandName="Deviation" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Near miss">
<ItemTemplate>
<asp:LinkButton ID="Near_miss" Text='<%# Eval("Near miss") %>' runat="server" CommandName="Near_miss" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Aid">
<ItemTemplate>
<asp:LinkButton ID="First_Aid" Text='<%# Eval("First Aid") %>' runat="server" CommandName="First_Aid" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fire">
<ItemTemplate>
<asp:LinkButton ID="Fire" Text='<%# Eval("Fire") %>' runat="server" CommandName="Fire" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Non-Reportable">
<ItemTemplate>
<asp:LinkButton ID="NonReportable" Text='<%# Eval("Non-Reportable") %>' runat="server" CommandName="NonReportable" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reportable">
<ItemTemplate>
<asp:LinkButton ID="Reportable" Text='<%# Eval("Reportable") %>' runat="server" CommandName="Reportable" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fatal">
<ItemTemplate>
<asp:LinkButton ID="Fatal" Text='<%# Eval("Fatal") %>' runat="server" CommandName="Fatal" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("DEPARTMENT"),
new DataColumn("Deviation"),
new DataColumn("Near miss"),
new DataColumn("First Aid"),
new DataColumn("Fire"),
new DataColumn("Non-Reportable"),
new DataColumn("Reportable"),
new DataColumn("Fatal")
});
dt.Rows.Add("EMG", "", "", "1", "", "", "", "");
dt.Rows.Add("EEMG", "", "", "", "1", "", "", "");
dt.Rows.Add("FES", "", "", "", "", "", "", "1");
dt.Rows.Add("IT", "", "", "", "", "1", "", "");
dt.Rows.Add("Mechanical Erection", "", "", "1", "", "", "", "");
GridView1.DataSource = dt;
GridView1.DataBind();
//Calculate Sum and display in Footer Row.
decimal deviation, near_miss, first_Aid, fire, non_Reportable, reportable, fatal;
deviation = dt.AsEnumerable().Sum(row => Convert.ToDecimal(!string.IsNullOrEmpty(row.Field<string>("Deviation")) ? row.Field<string>("Deviation") : "0"));
near_miss = dt.AsEnumerable().Sum(row => Convert.ToDecimal(!string.IsNullOrEmpty(row.Field<string>("Near miss")) ? row.Field<string>("Near miss") : "0"));
first_Aid = dt.AsEnumerable().Sum(row => Convert.ToDecimal(!string.IsNullOrEmpty(row.Field<string>("First Aid")) ? row.Field<string>("First Aid") : "0"));
fire = dt.AsEnumerable().Sum(row => Convert.ToDecimal(!string.IsNullOrEmpty(row.Field<string>("Fire")) ? row.Field<string>("Fire") : "0"));
non_Reportable = dt.AsEnumerable().Sum(row => Convert.ToDecimal(!string.IsNullOrEmpty(row.Field<string>("Non-Reportable")) ? row.Field<string>("Non-Reportable") : "0"));
reportable = dt.AsEnumerable().Sum(row => Convert.ToDecimal(!string.IsNullOrEmpty(row.Field<string>("Reportable")) ? row.Field<string>("Reportable") : "0"));
fatal = dt.AsEnumerable().Sum(row => Convert.ToDecimal(!string.IsNullOrEmpty(row.Field<string>("Fatal")) ? row.Field<string>("Fatal") : "0"));
GridView1.FooterRow.Cells[0].Text = "Total";
GridView1.FooterRow.Cells[0].HorizontalAlign = HorizontalAlign.Right;
GridView1.FooterRow.Cells[1].Text = deviation.ToString("N0");
GridView1.FooterRow.Cells[2].Text = near_miss.ToString("N0");
GridView1.FooterRow.Cells[3].Text = first_Aid.ToString("N0");
GridView1.FooterRow.Cells[4].Text = fire.ToString("N0");
GridView1.FooterRow.Cells[5].Text = non_Reportable.ToString("N0");
GridView1.FooterRow.Cells[6].Text = reportable.ToString("N0");
GridView1.FooterRow.Cells[7].Text = fatal.ToString("N0");
}
}
Screenshot