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.Change ASP.Net GridView Cell value based on another cell in RowDataBound event using C# and VB.Net<p>Hey <a class="username" rel="akhter"> akhter</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;gvCustomers&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; OnRowDataBound=&#34;gvCustomers_OnRowDataBound&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:BoundField DataField=&#34;Date&#34; HeaderText=&#34;Date&#34; /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID=&#34;txtHoures&#34; runat=&#34;server&#34; Text=&#39;&lt;%#Eval(&#34;Hours&#34;) %&gt;&#39;&gt;&lt;/asp:TextBox&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;Date&#34;, typeof(string)), new DataColumn(&#34;Hours&#34;, typeof(string)) }); dt.Rows.Add(&#34;Mudassar&#34;, &#34;2018-05-26 21:22:00&#34;, &#34;1&#34;); dt.Rows.Add(&#34;John&#34;, &#34;2018-05-27 21:22:00&#34;, &#34;1&#34;); dt.Rows.Add(&#34;test&#34;); gvCustomers.DataSource = dt; gvCustomers.DataBind(); } } protected void gvCustomers_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string date = e.Row.Cells[1].Text; if (date == &#34;&amp;nbsp;&#34;) { TextBox txtHours = e.Row.FindControl(&#34;txtHoures&#34;) as TextBox; txtHours.Text = &#34;0&#34;; } } }</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;Date&#34;, GetType(String)), New DataColumn(&#34;Hours&#34;, GetType(String))}) dt.Rows.Add(&#34;Mudassar&#34;, &#34;2018-05-26 21:22:00&#34;, &#34;1&#34;) dt.Rows.Add(&#34;John&#34;, &#34;2018-05-27 21:22:00&#34;, &#34;1&#34;) dt.Rows.Add(&#34;test&#34;) gvCustomers.DataSource = dt gvCustomers.DataBind() End If End Sub Protected Sub gvCustomers_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim date1 As String = e.Row.Cells(1).Text If date1 = &#34;&amp;nbsp;&#34; Then Dim txtHours As TextBox = TryCast(e.Row.FindControl(&#34;txtHoures&#34;), TextBox) txtHours.Text = &#34;0&#34; End If End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/sftFFMA.jpg" alt="" width="389" height="281" /></p>https://www.aspforums.net:443/Threads/173682/Change-ASPNet-GridView-Cell-value-based-on-another-cell-in-RowDataBound-event-using-C-and-VBNet/https://www.aspforums.net:443/Threads/173682/Change-ASPNet-GridView-Cell-value-based-on-another-cell-in-RowDataBound-event-using-C-and-VBNet/Mon, 31 Dec 2018 00:27:59 GMT