How To Change Color Of Datagrid Text …Depending On the value In Database….!!!!
//Following Ex. shows that if employee is absent then how to change the color of text in perticular cell…..
DataSet ds=new DataSet();
OdbcDataAdapter da=new OdbcDataAdapter("Select * from emp");
OdbcCommandBuilder cmd=new OdbcCommandBuilder(da);
da.fill(ds,"emp");
DataGrid1.DataSource =ds.Tables["emp"];
DataGrid1.DataBind();
//Code To change the for color if datagrid cell contains "A"
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DateTime dat=new DateTime();
dat=System.DateTime.Now;
int cur_day=dat.Day;
for(int i=0;i <=cur_day;i++)
{
string st = e.Item.Cells[i].Text;
if(st == "A")
e.Item.Cells[i].ForeColor= Color.Red;
}
}
By,
Aniruddha









