Sunday 10 June 2012

Change GridView row back color based on condition - Asp.net C#


protected void EmployeeAvailabilityGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
               if (e.Row.RowType == DataControlRowType.DataRow)
                {                  
                    if(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "AvailableStatus")) == "Out")
                    {
                        e.Row.BackColor = System.Drawing.Color.LightPink;
                    }
                }
            }
            catch (Exception ex)
            {
                //ErrorLabel.Text = ex.Message;
            }
        }

No comments:

Post a Comment