用户表 内容表
Id | name | Depaer || IDepartID | DepaerName | DepaerOpp ||
其中 Depaer=IDepartID
我的方法
C# code
protected void gvDepartMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//判断行类型
{
string gvId = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();//得到部门id
DepartInfo ev = DepartManager.GetDepartByID(gvId);
UserInfo user = (UserInfo)Session["CurrentUser"];
string userdepar=ev.IDepartID.Substring(0, 2);
if (userdepar ==user.Depaer)
{
e.Row.Cells[0].Text = ev.VcDepartName;
e.Row.Cells[1].Text=ev.DepaerOpp
}
else
{
e.Row.Visible = false;
}
}
}
行数显示 8行。 内容表里总共有33行数据
我在读取GridView的值时,
for (int i = 0; i < gvDepartMain.Rows.Count; i++)
{
}
gvDepartMain.Rows.Count=33.
我该怎么改
根据不同用户可以设置列的visible=false,你在读取时,判断列是否可见,如果可见,再读取
楼主给需求说的详细些。如果根据不同用户显示不同行数的话,那就是 产生的sql语句不同就是了