Home All Groups Group Topic Archive Search About

Hiding grid columns based on some value in row

Author
24 Oct 2007 2:41 PM
BillG
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

Author
27 Oct 2007 7:42 AM
Mansi Shah
Hi,

To change the visibility of any button or any control based on some
condition in grid, you can create 1 function after binding the grid.
Say,

..
grdcustomers.databind();
CheckGridForVisibility();

add this function to your page..

public void CheckGridForVisibility()
{
  for (int i = 0; i < grdCustomers.Rows.Count; i++)
        {
            Label lbldatetime =
(Label)grdCustomers.Rows[i].FindControl("lblDataTime");
        if (lbldatetime.Text == DateTime.Today.ToString())
            {
                Button btnedit =
grdCustomers.Rows[i].FindControl("btnEdit");
                btnedit.Visible = false;
            }
        }
}

Hope this will help you..


Regards,
Mansi Shah.

*** Sent via Developersdex http://www.developersdex.com ***