62,266
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 绑定GridView
/// </summary>
private void BindGrid()
{
// 初始化数据显示
string strWhere = "";
//string strTitle = this.txtTitle.Text;
//string strLWZH = this.txtZH.Text;
//string strLWLX = this.ddlLWLX.SelectedValue;
//// 初始化查询条件
//if (!strTitle.Equals(""))
//{
// strWhere += " and a.WJBT like '%" + strTitle + "%'";
//}
//if (!strLWZH.Equals(""))
//{
// strWhere += " and a.LWZH='" + strLWZH + "'";
//}
//if (!strLWLX.Equals(""))
//{
// strWhere += " and a.lwlx='" + strLWLX + "'";
//}
string UserId = "";
if (Request.Cookies["UserId"] != null)
{
UserId = Request.Cookies["UserId"].Value;
}
string UserName = bllUser.GetUserById(UserId);
// 设置分页控件
this.AspNetPager1.RecordCount = this.bllCycl.GetListCount(strWhere,UserName);
if (this.AspNetPager1.RecordCount == 0)
{
this.AspNetPager1.RecordCount = 1;
}
// 开始记录号
int pageId = AspNetPager1.CurrentPageIndex ;
// 结束记录号
int pageSize = this.AspNetPager1.PageSize;
// 获取记录列表
DataTable dt = bllCycl.GetList(strWhere, pageSize, pageId,UserName);
// 设置数据显示模式
if (dt.Rows.Count==0)
{
// 添加新行
dt.Rows.Add(dt.NewRow());
// 设置GridView数据源
this.GrvCycl.DataSource = dt;
this.GrvCycl.DataBind();
this.GrvCycl.Rows[0].Visible = false;
}
else
{
// 设置GridView数据源
this.GrvCycl.DataSource = dt;
this.GrvCycl.DataBind();
}
// 动态设置用户自定义文本内容
string customInfo = "总数:<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
customInfo += " 总页数:<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
customInfo += " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
// 设置分页控件的自定义信息
this.AspNetPager1.CustomInfoText = customInfo;
}