ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display sum of Column total in ASP.Net GridView Footer using RowDataBound event in C# and VB.Net<p>Hi <a class="username" rel="akhter"> akhter</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; ShowFooter=&#34;true&#34; OnRowDataBound=&#34;GridView1_OnRowDataBound&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;ItemName&#34; HeaderText=&#34;ItemName&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;Price&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label Text=&#39;&lt;%#Eval(&#34;Price&#34;) %&gt;&#39; ID=&#34;lblPrice&#34; runat=&#34;server&#34; /&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;asp:Label Text=&#39;&lt;%#Eval(&#34;Total&#34;) %&gt;&#39; ID=&#34;lblTotal&#34; runat=&#34;server&#34; /&gt; &lt;/FooterTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;ItemName&#34;, typeof(string)), new DataColumn(&#34;Price&#34;, typeof(decimal)) }); dt.Rows.Add(&#34;A&#34;, 10); dt.Rows.Add(&#34;B&#34;, -20); dt.Rows.Add(&#34;C&#34;, 5); dt.Rows.Add(&#34;D&#34;, -10); GridView1.DataSource = dt; GridView1.DataBind(); } } decimal total = 0; protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Label lblPrice = (e.Row.FindControl(&#34;lblPrice&#34;) as Label); total += Convert.ToDecimal(lblPrice.Text); } if (e.Row.RowType == DataControlRowType.Footer) { Label lblTotal = (e.Row.FindControl(&#34;lblTotal&#34;) as Label); lblTotal.Text = &#34;Total : &#34; + total.ToString(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;ItemName&#34;, GetType(String)), New DataColumn(&#34;Price&#34;, GetType(Decimal))}) dt.Rows.Add(&#34;A&#34;, 10) dt.Rows.Add(&#34;B&#34;, -20) dt.Rows.Add(&#34;C&#34;, 5) dt.Rows.Add(&#34;D&#34;, -10) GridView1.DataSource = dt GridView1.DataBind() End If End Sub Private total As Decimal = 0 Protected Sub GridView1_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim lblPrice As Label = (TryCast(e.Row.FindControl(&#34;lblPrice&#34;), Label)) total += Convert.ToDecimal(lblPrice.Text) End If If e.Row.RowType = DataControlRowType.Footer Then Dim lblTotal As Label = (TryCast(e.Row.FindControl(&#34;lblTotal&#34;), Label)) lblTotal.Text = &#34;Total : &#34; &amp; total.ToString() End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/bjPbMtJ.jpg" alt="" width="250" height="338" /></p>https://www.aspforums.net:443/Threads/103444/Display-sum-of-Column-total-in-ASPNet-GridView-Footer-using-RowDataBound-event-in-C-and-VBNet/https://www.aspforums.net:443/Threads/103444/Display-sum-of-Column-total-in-ASPNet-GridView-Footer-using-RowDataBound-event-in-C-and-VBNet/Wed, 15 May 2019 06:17:50 GMT