protected void gvMyGVName_RowDataBound(object sender, GridViewRowEventArgs e)
{
//The method is created as an example and was never tested(and even compiled)
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem as DataRowView;
DataRow dataRow = drv.Row;
if((DateTime)(dataRow[“MyDateColumn”])<=DateTime.Now)
{
DataControlFieldCell cell = GridViewHelper.CellBySortExpression(e.Row, “MyDateColumn”) as DataControlFieldCell;
GridViewHelper.DataControlField_SetNullDisplayText(cell, “Expired”);
}
}
}
//Function belongs to my GridViewHelper class.
/// <summary>
/// Hide link and add text control
/// </summary>
/// <param name=”cell”></param>
/// <param name=”nullDisplayText”></param>
public static void DataControlField_SetNullDisplayText(DataControlFieldCell cell, string nullDisplayText)
{
//TODO: implement derived from HyperLinkField class and set nullDisplayTex property
// TableCell cell = (TableCell) control;
Debug.Assert((cell.ContainingField is HyperLinkField) || (cell.ContainingField is ButtonField));//
if(cell.ContainingField is HyperLinkField)
{
if (((cell.Controls.Count < 1) || !(cell.Controls[0] is HyperLink)))
{
throw new ApplicationException(“HyperLinkField_WrongControlType”+ cell.ToString());
}
HyperLink link = (HyperLink)cell.Controls[0];
link.Visible = false;
}
if(cell.ContainingField is ButtonField)
{
if (((cell.Controls.Count < 1) || !(cell.Controls[0] is LinkButton)))
{
throw new ApplicationException(“ButtonField_WrongControlType” + cell.ToString());
}
LinkButton link = (LinkButton)cell.Controls[0];
link.Visible = false;
}
Label label = new Label();
label.Text = nullDisplayText;
label.Visible = true;
cell.Controls.Add(label);
}