Tuesday, January 31, 2012

change gridview row color based on condition c#

Change Row Color in asp.net Gridview base on conditions follow as stated


Suppose you placed agridview in the page as follows


<asp:GridView id="GridView1"  runat="Server" OnRowCreated="GridView1_OnRowCreated" autogenerateColumns="false"/>



Name
Student ID
marks
Status
Yourname
001
200
F
Myname
002
800
P
Ourname
003
500
F
protected void GridView1_OnRowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.DataItem != null)
        {
            DataRowView drv = (DataRowView)e.Row.DataItem;
            string catName = Convert.ToString(drv["Status"]);
            if (catName.Trim() == "F")
            {              
               e.Row.BackColor = Systmem.Drawing.Color.Red;         
            }
        }
    }

No comments:

Post a Comment