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) TextBox value to ASP.Net GridView using C# and VB.Net<p>Hi <a class="username" rel="SUJAYS"> SUJAYS</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p>You can use Session or ViewState to keep the record.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtValue&#34; OnTextChanged=&#34;TextChanged&#34; AutoPostBack=&#34;true&#34; /&gt;&lt;br /&gt;&lt;br /&gt; &lt;asp:GridView runat=&#34;server&#34; ID=&#34;gvDetails&#34; EmptyDataText=&#34;No record found.&#34; /&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 (!IsPostBack) { BindGridView(); } } private void BindGridView() { gvDetails.DataSource = ViewState[&#34;Data&#34;] as System.Data.DataTable; gvDetails.DataBind(); } protected void TextChanged(object sender, EventArgs e) { System.Data.DataTable dt; if (ViewState[&#34;Data&#34;] == null) { dt = new System.Data.DataTable(); dt.Columns.Add(&#34;Name&#34;); } else { dt = ViewState[&#34;Data&#34;] as System.Data.DataTable; } dt.Rows.Add((sender as TextBox).Text.Trim()); dt.AcceptChanges(); ViewState[&#34;Data&#34;] = dt; BindGridView(); }</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) Handles Me.Load If Not IsPostBack Then BindGridView() End If End Sub Private Sub BindGridView() gvDetails.DataSource = TryCast(ViewState(&#34;Data&#34;), Data.DataTable) gvDetails.DataBind() End Sub Protected Sub TextChanged(ByVal sender As Object, ByVal e As EventArgs) Dim dt As Data.DataTable If ViewState(&#34;Data&#34;) Is Nothing Then dt = New Data.DataTable() dt.Columns.Add(&#34;Name&#34;) Else dt = TryCast(ViewState(&#34;Data&#34;), Data.DataTable) End If dt.Rows.Add((TryCast(sender, TextBox)).Text.Trim()) dt.AcceptChanges() ViewState(&#34;Data&#34;) = dt BindGridView() End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/pNssMEc.gif" alt="" width="163" height="127" /></p>https://www.aspforums.net:443/Threads/104444/Pass-Send-TextBox-value-to-ASPNet-GridView-using-C-and-VBNet/https://www.aspforums.net:443/Threads/104444/Pass-Send-TextBox-value-to-ASPNet-GridView-using-C-and-VBNet/Fri, 23 Aug 2019 04:39:11 GMT