Tuesday, April 17, 2012

Grid Header hide and visible and header text change at runtime with RowDataBound event


protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
    {


        if (e.Row.RowType == DataControlRowType.Header)
        {
            if (Convert.ToString(Session["User"]).ToLower() == "Admin")
            {
                e.Row.Cells[0].Visible = false;
                e.Row.Cells[1].Visible = false;
                e.Row.Cells[6].Visible = true;
                e.Row.Cells[7].Visible = true;
                e.Row.Cells[12].Visible = true;
                e.Row.Cells[13].Visible = true;
            }
            else
            {
                e.Row.Cells[0].Visible = true;
                e.Row.Cells[1].Visible = true;
                e.Row.Cells[6].Visible = false;
                e.Row.Cells[7].Visible = false;
                e.Row.Cells[12].Visible = false;
                e.Row.Cells[13].Visible = false;
                e.Row.Cells[13].Text = "New Text";
            }
        }
   }

No comments:

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...