[英]How to display some column in grid view?
I want display specific column in data grid view for profile of user after log in the system but my problem it is display all columns in C# with asp.net sql server, any one can help me? 我希望在登录系统后在数据网格视图中显示特定列的用户配置文件,但我的问题是在C#中使用asp.net sql server显示所有列,任何人都可以帮助我吗?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["MyID"] != null)
{
if (!IsPostBack)
{
string Id1 = Request.QueryString["MyID"];
dt = d.userunfo(Id1);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
Do you want this like? 你想要这个吗?
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[index].Visible = false;
}
You can check this answer. 你可以查看这个答案。
确保已将column的Datasource属性指定为数据库列名
Add OnRowDataBound
of your GridView
添加GridView
OnRowDataBound
<asp:GridView ID="GridViewID" runat="server" OnRowDataBound="gvTest_RowDataBound" >
in RowDataBound
在RowDataBound
First, check the roles of user and then you can check the condition and hide your column 首先,检查用户的角色,然后您可以检查条件并隐藏列
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check User Type
int userType = //Your User Type Here;
if (userType == 1)
{
GridViewID.Columns[15].Visible = false;
}
else if (userType == 2 || userType == 3)
{
GridViewID.Columns[5].Visible = false;
GridViewID.Columns[6].Visible = false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.