Monday, February 14, 2011

Looping Through GridView Rows

example: loop through all the rows and turn on / off link buttons if the user does not have a specific role
string role = Session["roleName"].ToString();
foreach (GridViewRow row in gvApplication.Rows)
{
           LinkButton lbUpdate = (LinkButton)row.FindControl("Update");
            LinkButton lbDelete = (LinkButton)row.FindControl("Delete");
            try
            {
                if (role == "SUPERUSER" || role == "ADMINISTRATOR")
                {
                    lbUpdate.Enabled = true;
                    lbDelete.Enabled = true;
                }
                else
                {
                    lbUpdate.Enabled = false;
                    lbDelete.Enabled = false;
                }
            }
     }

No comments:

Post a Comment