Pages

About Me

My photo
ForEach(Minute in MyLife) MyExperience ++;

Saturday, July 2, 2011

Change gridview row style dynamically ...

Inside row databound ,
e.Row.Font.Bold = true;

e.Row.Style.Add("color","White");
e.Row.Style.Add("background-color", hf.Value);
e.Row.BackColor = Color.White; ( add namespace system.drawing)


Example :
protected void Gv_NOTICE_LIST_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HiddenField HF_Status = (HiddenField)e.Row.FindControl("Hf_NOTICE_STATUS");
ImageButton Delete = (ImageButton)e.Row.FindControl("ImgB_DELETE");
if (HF_Status.Value != "")
{
if (HF_Status.Value == "0")
{
Label Lbl_Status = (Label)e.Row.FindControl("Lbl_Notice");
Lbl_Status.Text = "Unread";
Delete.Enabled = false;
e.Row.Font.Bold = true;
Delete.Attributes.Add ("title", "An unreaded notice cant be delete");

}
else if (HF_Status.Value == "1")
{
Label Lbl_Status = (Label)e.Row.FindControl("Lbl_Notice");
Lbl_Status.Text = "Read";
Delete.Enabled = true;

}

//else if (HF_Status.Value == "2")
//{
// Label Lbl_Status = (Label)e.Row.FindControl("Lbl_Notice");
// Lbl_Status.Text = "Deleted";
//}
}
}
}

2 comments: