Home > ASP.Net > Format GridView Rows Based On Data In ASP.Net

Format GridView Rows Based On Data In ASP.Net


Hi all,

try this example to Format GridView Rows Based On Data In ASP.Net

FormatedGridview

We can format Gridview Rows based on Data using the following code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class FormateFieldInGridview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

public string FormatEmpSal(object objEmpSal)
{
if (objEmpSal.Equals(DBNull.Value.ToString()))
{
return "<span style='color: red; font-weight: bold;'>EmpSal is Blank</span>";
}
else
{
decimal Sal = Convert.ToDecimal(objEmpSal);
if (Sal <= 0)
{
return "<span style='color: red; font-weight: bold;'>EmpSal is Zero</span>";
}
else
{
return Sal.ToString();
}
}
}
}

then we can Call this method in GridView

FormatedGridviewCode

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: