Tuesday, June 2, 2009

Show Gridview Row in Red Color on the basis of Inner Value

Write following code in Design:

asp:TemplateField HeaderText="Status"
ItemTemplate
asp:Label ID="Lblstatus" runat="server" Text='%# Eval("status") %'/asp:Label
/ItemTemplate
/asp:TemplateField

Write following code in .cs file:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = (Label)e.Row.FindControl("Lblstatus");
if ((string)DataBinder.Eval(e.Row.DataItem, "status").ToString().ToUpper() == "D")
{
e.Row.BackColor = System.Drawing.Color.Red;
e.Row.Font.Bold = true;
}
}
}

No comments: