How to format Gridview rows on basis of data in asp.net ?


GridFormate
Hi

We can format asp.net gridview rows on basis of data using C# helper method like this


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();
            }
        }
    }
}

In aspx bind this method like this

FormateGridCode

Advertisements
Posted in Asp.net. 1 Comment »

One Response to “How to format Gridview rows on basis of data in asp.net ?”

  1. Sumith Says:

    Nice One….


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: