hiding columns in gird based on column values

N

news.microsoft.com

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

IfThenElse

In the databind event handler of your datagrid check for the dateoccured on
each row and hide the button(s).
 
M

Mark Rae [MVP]

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top