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.Transfer Selected Rows from one GridView to Another with Total using C# and VB.Net in ASP.Net<p>Hi&nbsp;VinitaAkha,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#39;[id*=chk]&#39;).on(&#39;change&#39;, function () { var value = 0; $(&#39;[id*=chk]:checked&#39;).each(function () { var row = $(this).closest(&#39;tr&#39;); value = value + parseInt(row.find(&#39;[id*=Total]&#39;).html()); }); $(&#34;[id*=gvData] [id*=lblGrandTotal]&#34;).html(value); $(&#34;[id*=gvSelected] [id*=lblGrandTotal]&#34;).html(value); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;asp:GridView ID=&#34;gvData&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; ShowFooter=&#34;true&#34; Width=&#34;100%&#34;&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText=&#34;Select&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID=&#34;chk&#34; runat=&#34;server&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Name&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Name&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Name&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Email&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Email&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Email&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;State&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;State&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;State&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;District&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;District&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;District&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Address&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Address&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Address&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Contact&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Contact&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Contact&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;PQuantity&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;PQuantity&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;PQuantity&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Quantity&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Quantity&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Quantity&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Total&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Total&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Total&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; Total : &lt;asp:Label ID=&#34;lblGrandTotal&#34; runat=&#34;server&#34; /&gt; &lt;/FooterTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;&lt;br /&gt; &lt;asp:Button ID=&#34;Button1&#34; runat=&#34;server&#34; Text=&#34;Add&#34; OnClick=&#34;Button1_Click&#34; /&gt; &lt;hr /&gt; &lt;u&gt;Selected Rows&lt;/u&gt; &lt;br /&gt;&lt;br /&gt; &lt;asp:GridView ID=&#34;gvSelected&#34; runat=&#34;server&#34; Width=&#34;100%&#34; ShowFooter=&#34;true&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:BoundField DataField=&#34;State&#34; HeaderText=&#34;State&#34; /&gt; &lt;asp:BoundField DataField=&#34;District&#34; HeaderText=&#34;District&#34; /&gt; &lt;asp:BoundField DataField=&#34;Address&#34; HeaderText=&#34;Address&#34; /&gt; &lt;asp:BoundField DataField=&#34;Email&#34; HeaderText=&#34;Email&#34; /&gt; &lt;asp:BoundField DataField=&#34;Contact&#34; HeaderText=&#34;Contact&#34; /&gt; &lt;asp:BoundField DataField=&#34;PQuantity&#34; HeaderText=&#34;PQuantity&#34; /&gt; &lt;asp:BoundField DataField=&#34;Quantity&#34; HeaderText=&#34;Quantity&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;Total&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;Total&#34; runat=&#34;server&#34; Text=&#39;&lt;%# Eval(&#34;Total&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; Total : &lt;asp:Label ID=&#34;lblGrandTotal&#34; runat=&#34;server&#34; /&gt; &lt;/FooterTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></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[10] { new DataColumn(&#34;Role&#34;, typeof(string)), new DataColumn(&#34;Email&#34;, typeof(string)), new DataColumn(&#34;Contact&#34;,typeof(string)), new DataColumn(&#34;State&#34;, typeof(string)), new DataColumn(&#34;District&#34;, typeof(string)), new DataColumn(&#34;Address&#34;,typeof(string)), new DataColumn(&#34;Name&#34;, typeof(string)), new DataColumn(&#34;Quantity&#34;, typeof(int)), new DataColumn(&#34;PQuantity&#34;,typeof(int)), new DataColumn(&#34;Total&#34;,typeof(int))}); dt.Rows.Add(&#34;Role 1&#34;, &#34;Email 1&#34;, &#34;Contact 1&#34;, &#34;State 1&#34;, &#34;District 1&#34;, &#34;Address 1&#34;, &#34;Name 1&#34;, 10, 5, 50); dt.Rows.Add(&#34;Role 2&#34;, &#34;Email 2&#34;, &#34;Contact 2&#34;, &#34;State 2&#34;, &#34;District 2&#34;, &#34;Address 2&#34;, &#34;Name 2&#34;, 20, 5, 100); dt.Rows.Add(&#34;Role 3&#34;, &#34;Email 3&#34;, &#34;Contact 3&#34;, &#34;State 3&#34;, &#34;District 3&#34;, &#34;Address 3&#34;, &#34;Name 3&#34;, 15, 5, 75); dt.Rows.Add(&#34;Role 4&#34;, &#34;Email 4&#34;, &#34;Contact 4&#34;, &#34;State 4&#34;, &#34;District 4&#34;, &#34;Address 4&#34;, &#34;Name 4&#34;, 12, 5, 60); gvData.DataSource = dt; gvData.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { decimal total = 0; try { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[9] { new DataColumn(&#34;Name&#34;), new DataColumn(&#34;Quantity&#34;), new DataColumn(&#34;Contact&#34;), new DataColumn(&#34;Email&#34;), new DataColumn(&#34;State&#34;), new DataColumn(&#34;District&#34;), new DataColumn(&#34;Address&#34;), new DataColumn(&#34;PQuantity&#34;), new DataColumn(&#34;Total&#34;) }); foreach (GridViewRow row in gvData.Rows) { if (row.RowType == DataControlRowType.DataRow) { CheckBox chkRow = (row.Cells[0].FindControl(&#34;chk&#34;) as CheckBox); if (chkRow.Checked) { string Name = (row.Cells[1].FindControl(&#34;Name&#34;) as Label).Text; string Quantity = (row.Cells[2].FindControl(&#34;Quantity&#34;) as Label).Text; string Contact = (row.Cells[3].FindControl(&#34;Contact&#34;) as Label).Text; string Email = (row.Cells[4].FindControl(&#34;Email&#34;) as Label).Text; string State = (row.Cells[5].FindControl(&#34;State&#34;) as Label).Text; string District = (row.Cells[6].FindControl(&#34;District&#34;) as Label).Text; string Address = (row.Cells[7].FindControl(&#34;Address&#34;) as Label).Text; string PQuantity = (row.Cells[8].FindControl(&#34;PQuantity&#34;) as Label).Text; string Total = (row.Cells[9].FindControl(&#34;Total&#34;) as Label).Text; total += Convert.ToDecimal(Total); dt.Rows.Add(Name, Quantity, Contact, Email, State, District, Address, PQuantity, Total); } } } gvSelected.DataSource = dt; gvSelected.DataBind(); (gvSelected.FooterRow.FindControl(&#34;lblGrandTotal&#34;) as Label).Text = total.ToString(); } catch (Exception ex) { Response.Write(ex); } }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not Me.IsPostBack Then Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn(9) {New DataColumn(&#34;Role&#34;, GetType(String)), New DataColumn(&#34;Email&#34;, GetType(String)), New DataColumn(&#34;Contact&#34;, GetType(String)), New DataColumn(&#34;State&#34;, GetType(String)), New DataColumn(&#34;District&#34;, GetType(String)), New DataColumn(&#34;Address&#34;, GetType(String)), New DataColumn(&#34;Name&#34;, GetType(String)), New DataColumn(&#34;Quantity&#34;, GetType(Integer)), New DataColumn(&#34;PQuantity&#34;, GetType(Integer)), New DataColumn(&#34;Total&#34;, GetType(Integer))}) dt.Rows.Add(&#34;Role 1&#34;, &#34;Email 1&#34;, &#34;Contact 1&#34;, &#34;State 1&#34;, &#34;District 1&#34;, &#34;Address 1&#34;, &#34;Name 1&#34;, 10, 5, 50) dt.Rows.Add(&#34;Role 2&#34;, &#34;Email 2&#34;, &#34;Contact 2&#34;, &#34;State 2&#34;, &#34;District 2&#34;, &#34;Address 2&#34;, &#34;Name 2&#34;, 20, 5, 100) dt.Rows.Add(&#34;Role 3&#34;, &#34;Email 3&#34;, &#34;Contact 3&#34;, &#34;State 3&#34;, &#34;District 3&#34;, &#34;Address 3&#34;, &#34;Name 3&#34;, 15, 5, 75) dt.Rows.Add(&#34;Role 4&#34;, &#34;Email 4&#34;, &#34;Contact 4&#34;, &#34;State 4&#34;, &#34;District 4&#34;, &#34;Address 4&#34;, &#34;Name 4&#34;, 12, 5, 60) gvData.DataSource = dt gvData.DataBind() End If End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim total As Decimal = 0 Try Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn(8) {New DataColumn(&#34;Name&#34;), New DataColumn(&#34;Quantity&#34;), New DataColumn(&#34;Contact&#34;), New DataColumn(&#34;Email&#34;), New DataColumn(&#34;State&#34;), New DataColumn(&#34;District&#34;), New DataColumn(&#34;Address&#34;), New DataColumn(&#34;PQuantity&#34;), New DataColumn(&#34;Total&#34;)}) For Each row As GridViewRow In gvData.Rows If row.RowType = DataControlRowType.DataRow Then Dim chkRow As CheckBox = (TryCast(row.Cells(0).FindControl(&#34;chk&#34;), CheckBox)) If chkRow.Checked Then Dim Name As String = (TryCast(row.Cells(1).FindControl(&#34;Name&#34;), Label)).Text Dim Quantity As String = (TryCast(row.Cells(2).FindControl(&#34;Quantity&#34;), Label)).Text Dim Contact As String = (TryCast(row.Cells(3).FindControl(&#34;Contact&#34;), Label)).Text Dim Email As String = (TryCast(row.Cells(4).FindControl(&#34;Email&#34;), Label)).Text Dim State As String = (TryCast(row.Cells(5).FindControl(&#34;State&#34;), Label)).Text Dim District As String = (TryCast(row.Cells(6).FindControl(&#34;District&#34;), Label)).Text Dim Address As String = (TryCast(row.Cells(7).FindControl(&#34;Address&#34;), Label)).Text Dim PQuantity As String = (TryCast(row.Cells(8).FindControl(&#34;PQuantity&#34;), Label)).Text Dim Total As String = (TryCast(row.Cells(9).FindControl(&#34;Total&#34;), Label)).Text total += Convert.ToDecimal(Total) dt.Rows.Add(Name, Quantity, Contact, Email, State, District, Address, PQuantity, Total) End If End If Next gvSelected.DataSource = dt gvSelected.DataBind() (TryCast(gvSelected.FooterRow.FindControl(&#34;lblGrandTotal&#34;), Label)).Text = total.ToString() Catch ex As Exception Response.Write(ex) End Try End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/XCyEUp3.gif" alt="" width="472" height="288" /></span></strong></p>https://www.aspforums.net:443/Threads/105446/Transfer-Selected-Rows-from-one-GridView-to-Another-with-Total-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/105446/Transfer-Selected-Rows-from-one-GridView-to-Another-with-Total-using-C-and-VBNet-in-ASPNet/Thu, 01 Aug 2019 05:49:25 GMT