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.Increment decrement TextBox value inside GridView using C# and VB.Net in ASP.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 runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; ID=&#34;GridView1&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;Minus&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Button Text=&#34;-&#34; runat=&#34;server&#34; OnClick=&#34;CalculateMinus&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;QTY&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtQuatntity&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Plus&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID=&#34;Button1&#34; Text=&#34;+&#34; runat=&#34;server&#34; OnClick=&#34;CalculatePlus&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField=&#34;Price&#34; HeaderText=&#34;Price&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;Total&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;lblTotal&#34; runat=&#34;server&#34; /&gt; &lt;/ItemTemplate&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;Name&#34;, typeof(string)), new DataColumn(&#34;Price&#34;, typeof(int)) }); dt.Rows.Add(&#34;Normal Wax- Full Hands&#34;, 100); dt.Rows.Add(&#34;Normal Wax- Half Hands&#34;, 100); dt.Rows.Add(&#34;Normal Wax- Neck&#34;, 200); GridView1.DataSource = dt; GridView1.DataBind(); } } protected void CalculateMinus(object sender, EventArgs e) { Button btn = (sender) as Button; GridViewRow row = (GridViewRow)btn.NamingContainer; int qty = Convert.ToInt16((row.FindControl(&#34;txtQuatntity&#34;) as TextBox).Text); int price = Convert.ToInt16(row.Cells[4].Text); (row.FindControl(&#34;lblTotal&#34;) as Label).Text = (qty - price).ToString(); } protected void CalculatePlus(object sender, EventArgs e) { Button btn = (sender) as Button; GridViewRow row = (GridViewRow)btn.NamingContainer; int qty = Convert.ToInt16((row.FindControl(&#34;txtQuatntity&#34;) as TextBox).Text); int price = Convert.ToInt16(row.Cells[4].Text); (row.FindControl(&#34;lblTotal&#34;) as Label).Text = (qty + price).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;Name&#34;, GetType(String)), New DataColumn(&#34;Price&#34;, GetType(Integer))}) dt.Rows.Add(&#34;Normal Wax- Full Hands&#34;, 100) dt.Rows.Add(&#34;Normal Wax- Half Hands&#34;, 100) dt.Rows.Add(&#34;Normal Wax- Neck&#34;, 200) GridView1.DataSource = dt GridView1.DataBind() End If End Sub Protected Sub CalculateMinus(ByVal sender As Object, ByVal e As EventArgs) Dim btn As Button = TryCast((sender), Button) Dim row As GridViewRow = CType(btn.NamingContainer, GridViewRow) Dim qty As Integer = Convert.ToInt16((TryCast(row.FindControl(&#34;txtQuatntity&#34;), TextBox)).Text) Dim price As Integer = Convert.ToInt16(row.Cells(4).Text) TryCast(row.FindControl(&#34;lblTotal&#34;), Label).Text = (qty - price).ToString() End Sub Protected Sub CalculatePlus(ByVal sender As Object, ByVal e As EventArgs) Dim btn As Button = TryCast((sender), Button) Dim row As GridViewRow = CType(btn.NamingContainer, GridViewRow) Dim qty As Integer = Convert.ToInt16((TryCast(row.FindControl(&#34;txtQuatntity&#34;), TextBox)).Text) Dim price As Integer = Convert.ToInt16(row.Cells(4).Text) TryCast(row.FindControl(&#34;lblTotal&#34;), Label).Text = (qty + price).ToString() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/U7EQphK.gif" alt="" width="485" height="267" /></p>https://www.aspforums.net:443/Threads/566355/Increment-decrement-TextBox-value-inside-GridView-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/566355/Increment-decrement-TextBox-value-inside-GridView-using-C-and-VBNet-in-ASPNet/Mon, 26 Aug 2019 03:57:47 GMT