hi
gridview formatting dynamically change gridview cell color based on cell value in AspNet
my code:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
using (DataSet ds = new DataSet())
{
int i;
for (i = 0; i < 20; i++)
{
if (System.IO.File.Exists(Server.MapPath("~/Files/SiteInfo" + i + ".xml")))
{
ds.ReadXml(Server.MapPath("~/Files/SiteInfo" + i + ".xml"));
}
}
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGrid();
}
What I have tried:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int Temperature = int.Parse(e.Row.Cells[4].Text);
if (Temperature <= 50)
e.Row.Cells[4].BackColor = System.Drawing.Color.Red;
else if (Temperature <= 30)
e.Row.Cells[4].BackColor = System.Drawing.Color.Yellow;
else
e.Row.Cells[4].BackColor = System.Drawing.Color.Green;
}
}
i tried this code but not working..
http://postimg.org/image/n1qyfjpmv/
please help me.