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.Pass (Send) ASP.Net GridView data to another on Button Click using C# and VB.Net<p>Hi <a class="username" rel="SUJAYS"> SUJAYS</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 runat=&#34;server&#34; ID=&#34;GridView1&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Id&#34; HeaderText=&#34;Id&#34; /&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:BoundField DataField=&#34;Country&#34; HeaderText=&#34;Country&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;br /&gt; &lt;asp:Button Text=&#34;Transfer&#34; runat=&#34;server&#34; OnClick=&#34;Transfer&#34; /&gt; &lt;br /&gt; &lt;asp:GridView runat=&#34;server&#34; ID=&#34;GridView2&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Id&#34; HeaderText=&#34;Id&#34; /&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:BoundField DataField=&#34;Country&#34; HeaderText=&#34;Country&#34; /&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;Id&#34;, typeof(int)), new DataColumn(&#34;Name&#34;, typeof(string)), new DataColumn(&#34;Country&#34;, typeof(string)) }); dt.Rows.Add(1, &#34;John Hammod&#34;, &#34;USA&#34;); dt.Rows.Add(1, &#34;Mudassar Khan&#34;, &#34;India&#34;); dt.Rows.Add(1, &#34;Robert downy&#34;, &#34;France&#34;); dt.Rows.Add(1, &#34;Suzzain Mathew&#34;, &#34;Rusia&#34;); GridView1.DataSource = dt; GridView1.DataBind(); ViewState[&#34;dt&#34;] = dt; } } protected void Transfer(object sender, EventArgs e) { DataTable dt = ViewState[&#34;dt&#34;] as DataTable; GridView2.DataSource = dt; GridView2.DataBind(); }</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;Id&#34;, GetType(Integer)), New DataColumn(&#34;Name&#34;, GetType(String)), New DataColumn(&#34;Country&#34;, GetType(String))}) dt.Rows.Add(1, &#34;John Hammod&#34;, &#34;USA&#34;) dt.Rows.Add(1, &#34;Mudassar Khan&#34;, &#34;India&#34;) dt.Rows.Add(1, &#34;Robert downy&#34;, &#34;France&#34;) dt.Rows.Add(1, &#34;Suzzain Mathew&#34;, &#34;Rusia&#34;) GridView1.DataSource = dt GridView1.DataBind() ViewState(&#34;dt&#34;) = dt End If End Sub Protected Sub Transfer(ByVal sender As Object, ByVal e As EventArgs) Dim dt As DataTable = TryCast(ViewState(&#34;dt&#34;), DataTable) GridView2.DataSource = dt GridView2.DataBind() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/cv2c05t.gif" alt="" width="250" height="393" /></p>https://www.aspforums.net:443/Threads/248655/Pass-Send-ASPNet-GridView-data-to-another-on-Button-Click-using-C-and-VBNet/https://www.aspforums.net:443/Threads/248655/Pass-Send-ASPNet-GridView-data-to-another-on-Button-Click-using-C-and-VBNet/Fri, 23 Aug 2019 03:32:29 GMT