hiding columns in gird based on column values

Discussion in 'ASP .Net' started by news.microsoft.com, Oct 25, 2007.

  1. 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
     
    news.microsoft.com, Oct 25, 2007
    #1
    1. Advertising

  2. news.microsoft.com

    IfThenElse Guest

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

    "news.microsoft.com" <> wrote in message
    news:...
    >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
    >
    >
     
    IfThenElse, Oct 25, 2007
    #2
    1. Advertising

  3. "news.microsoft.com" <> wrote in message
    news:...

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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Oct 25, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carl
    Replies:
    0
    Views:
    586
  2. yawnmoth
    Replies:
    1
    Views:
    714
    Martin Honnen
    May 25, 2009
  3. ton
    Replies:
    2
    Views:
    207
    Alvin Bruney [MVP]
    Feb 11, 2004
  4. RGB
    Replies:
    5
    Views:
    224
    John Saunders
    Jan 7, 2005
  5. Ste
    Replies:
    41
    Views:
    812
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page