8,497
社区成员
发帖
与我相关
我的任务
分享
private void BindGrid2()
{
int titleID = GetSelectedDataKeyID(Grid1);
if (titleID == -1)
{
Grid2.RecordCount = 0;
Grid2.DataSource = null;
Grid2.DataBind();
}
else
{
IQueryable<User> q = DB.Users;
// 在用户名称中搜索
string searchText = ttbSearchUser.Text.Trim();
if (!String.IsNullOrEmpty(searchText))
{
q = q.Where(u => u.Name.Contains(searchText));
}
q = q.Where(u => u.Name != "admin");
// 过滤选中岗位下的所有用户(这句如果注释掉就没问题)
q = q.Where(r => r.Titles.Any(n => n.ID == titleID));
// 在查询添加之后,排序和分页之前获取总记录数
Grid2.RecordCount = q.Count();
// 排列和分页
q = SortAndPage<User>(q, Grid2);
try
{
Grid2.DataSource = q;
Grid2.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}