I have a grid that has icons for 2 buttons edit and delete on each row. I
would like to make the buttons invisible if the dateoccured in the record in
the row is older than this week. How do I do that?
Bill
In the databind event handler of your datagrid check for the dateoccured on
each row and hide the button(s).
>I have a grid that has icons for 2 buttons edit and delete on each row. I
> would like to make the buttons invisible if the dateoccured in the record
> in
> the row is older than this week. How do I do that?
>
> Bill
>I have a grid that has icons for 2 buttons edit and delete on each row. I
> would like to make the buttons invisible if the dateoccured in the record
> in
> the row is older than this week. How do I do that?
<asp:GridView ID="MyGrid" runat="server"
OnRowDataBound="MyGrid_RowDataBound" ........ />
protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToDateTime(e.Row.Cells[0].Text) <
DateTime.Now.AddDays(-7))
{
e.Row.Cells[2].FindControl("MyEditButton").Visible = false;
e.Row.Cells[2].FindControl("MyDeleteButton").Visible = false;
}
}
}
Obviously, change the column indexes as necessary.
N.B. setting a column's control(s) Visible property to false isn't the same
as hiding the column, which was the title of your OP...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net