[RESOLVED]How to change color of a gridview as per value

How to change color of a gridview as per value

use Backcolor property to change backcolor of grid view

this llink will help you

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_properties.aspx

If want to change Gridview row back color

protected void RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        //check role
         if (condition)
           e.Row.BackColor = Color.Red;
         else
           e.Row.BackColor = Color.Green;
        //or set you individual control background
         //get any control
          var chk = (CheckBox)e.Row.FindControl("chkb");
         //set background
          chk.BackColor = Color.Red;//etc
     }
}

You can set css dynamically to the textbox

CssClass="yourcss"

  <asp:TextBox ID="txt_ReasonCode" onchange="disableNextStatusButtons()" runat="server" Text='<%# Bind("ReasonCode") %>'
                Enabled='<%# (Roles.IsUserInRole("İhracat Uzmanı") && Session["Status"].ToString()=="3") %>'
                CssClass='<%# (Roles.IsUserInRole("İhracat Uzmanı") && Session["Status"].ToString()=="NormalCss").ToString()=="true"?"yellowcss":"othercss"  %>'
                Width="40px"></asp:TextBox>

I hope this will work for you.

What background are you changing?

  • The entire GridView?
  • A row, based on a value in the row?
  • A cell in a row, based on a value in the row?

Are your columns BoundFields or TemplateFields?

Leave a Reply