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 Background color based on condition using C# and VB.Net<p>Hi <a class="username" rel="simflex"> simflex</a>,</p> <p>Refer below link and sample.</p> <h1 class="header"><a title="Change Background color of GridView Row using RowDataBound event in ASP.Net using C# and VB.Net'a" href="https://www.aspsnippets.com/Articles/Change-Background-color-of-GridView-Row-using-RowDataBound-event-in-ASPNet-using-C-and-VBNet.aspx">Change Background color of GridView Row using RowDataBound event in ASP.Net using C# and VB.Net</a></h1> <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_RowDataBound&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;CustomerId&#34; HeaderText=&#34;Id&#34; /&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:HyperLink runat=&#34;server&#34; NavigateUrl=&#34;~/CS.aspx&#34; ID=&#34;HyperLink1&#34; Text=&#34;Listen&#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; using System.Drawing;</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;CustomerId&#34;, typeof(int)), new DataColumn(&#34;Name&#34;, typeof(string)) }); dt.Rows.Add(1, &#34;Mudassar Khan&#34;); dt.Rows.Add(2, &#34;John Hammod&#34;); dt.Rows.Add(3, &#34;Rober&#34;); dt.Rows.Add(1, &#34;Suzzain&#34;); this.gvCustomers.DataSource = dt; this.gvCustomers.DataBind(); } } protected void gvCustomers_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[0].Text == &#34;1&#34;) { e.Row.Cells[2].BackColor = Color.Red; } } }</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/iCHUwhs.jpg" alt="" width="249" height="291" /></p>https://www.aspforums.net:443/Threads/972868/Change-ASPNet-GridView-Cell-Background-color-based-on-condition-using-C-and-VBNet/https://www.aspforums.net:443/Threads/972868/Change-ASPNet-GridView-Cell-Background-color-based-on-condition-using-C-and-VBNet/Mon, 03 Jun 2019 08:58:57 GMT