Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


How to hide grid column based on user log in in asp.net?

For example i have given admin role id is '1' and other users role id '2'. If normal user log in then grid should hide.


Thanks and Regards,
Murali
Posted

Try like this:
if(session["normaluser"]!=null)
{
gridview1.columns[0].visible=false;
}

else if(session["admin"]!=null)
{
gridview1.columns[0].visible=true;
}
 
Share this answer
 
v2
ASPX.CS :

C#
public bool isVisibleColumn;

protected void Page_Load(object sender, EventArgs e)
{

 if (Request.QueryString["name"] != null && Request.QueryString 
     ["name"] == "xyz")
 {
     isVisibleColumn = true;
 }
 else
 {
   isVisibleColumn = false;
 }

  this.GridView2.Columns[3].Visible = isVisibleColumn;
  this.BindData();

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900