一个文本要显示“公有多少条记录,当前第几页,共有多少页”
公有多少条记录,共有多少页可以在检索数据库时得到。
但是当前第几页是动态变化的(在paging事件可以得到页码)。我怎么去实现更文本的当前第几页呢?
我想了一下啊
用
this.lblRecord.Text=string.Format("公有{0}条记录,当前第{1}页,共有{2}页","","","")这样子
但是我怎样去更新中间的那个参数呢(当前第几页)?
公有多少条记录,共有多少页可以在检索数据库时得到。
但是当前第几页是动态变化的(在paging事件可以得到页码)。我怎么去实现更文本的当前第几页呢?
我想了一下啊
用
this.lblRecord.Text=string.Format("公有{0}条记录,当前第{1}页,共有{2}页","","","")这样子
但是我怎样去更新中间的那个参数呢(当前第几页)?
解决方案 »
- 调查,IHttpHandler或者.ashx的应用场景?
- datalist怎么不显示全部内容
- 组件图像的输出格式
- 求横向菜单代码,用javascript做!!!!特急,趴求!!!!!!
- 用javascript控制按钮失效后再生效.
- 。。。NND。。。这事还真TMD的见鬼了???瞅瞅。。。
- dropdownlist自动选中键盘输入的项
- <a href="xxx.pdf"></a>为什么在IE里面不是直接打开,在火狐,谷歌里能直接打开
- 在DataGrid中添加了一列CheckBox的问题
- 微软Office组件调用的奇怪问题,真诚求大神解答
- 急!!!!望高手帮忙下!!!!
- 请问一个关于CKeditor上传按钮的问题
至于1 2 3 4数字分页法,只要你知道了当前页,总页数就好判断了
就是循环一个范围内的值
例如刚开始要显示1 2 3 4 5 6
首先判断当前页是否>=6,如果大于的话就循环append 0-6
然后当点击数字分页的时候,当点到5时,你在判断一下从当前页要偏移几个数,在从当前页减去偏移数,加上偏移数,显示的就是这个范围的数字了。等等主要是逻辑理清了就明白
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Job_Document_Document_List : System.Web.UI.Page
{
//总记录数
private static int RecordCount;
//页面大小
private static int PageSize = 20;
//页面总数
private static int PageCount;
//当前页码
private static int PageIndex = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PageParmInit();
GetPage();
}
} /// <summary>
/// 初始化分页参数
/// </summary>
private void PageParmInit()
{
PageIndex = 1;
Document document = new Document();
CompositeCategory category = new CompositeCategory();
SessionLogin login = (this.Master as MasterPage_Admin).currLogin; DataSet data = document.GetDocuments(login.Id);
RecordCount = data.Tables[0].Rows.Count;
PageCount = RecordCount / PageSize;
if (RecordCount % PageSize > 0) PageCount += 1;
} /// <summary>
/// 设置分页控件的状态
/// </summary>
private void SetControl()
{
this.lblRecordCount.Text = RecordCount.ToString();
this.lblPageCount.Text = PageCount.ToString();
this.lblPageIndex.Text = PageIndex.ToString();
//下一页按钮
if (PageIndex >= PageCount)
{
this.btnNext.Enabled = false;
this.btnNext.ImageUrl = "~/Images/control/button/next1_en_false.gif";
}
else
{
this.btnNext.Enabled = true;
this.btnNext.ImageUrl = "~/Images/control/button/next1_en_true.gif";
}
//上一页按钮
if (PageIndex < 2)
{
this.btnPrev.Enabled = false;
this.btnPrev.ImageUrl = "~/Images/control/button/prev1_en_false.gif";
}
else
{
this.btnPrev.Enabled = true;
this.btnPrev.ImageUrl = "~/Images/control/button/prev1_en_true.gif";
}
} /// <summary>
/// 加载当前页的数据到控件
/// </summary>
private void GetPage()
{
Document document = new Document();
CompositeCategory category = new CompositeCategory();
SessionLogin login = (this.Master as MasterPage_Admin).currLogin; DataSet data = document.GetDocuments(login.Id, PageSize, PageIndex);
DataSet item = new DataSet(); if (data.Tables[0].Rows.Count <= 0)
{
HtmlTableRow newRow = new HtmlTableRow();
HtmlTableCell col_null = new HtmlTableCell();
col_null.InnerHtml = "您目前没有创建任何文档!";
col_null.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
col_null.Style.Add(HtmlTextWriterStyle.Color, "blue");
col_null.ColSpan = 5;
newRow.Cells.Add(col_null);
this.tbDocuments.Rows.Add(newRow);
return;
} // 填充数据
for (int j = 0; j < data.Tables[0].Rows.Count; j++)
{
DataRow curRow = data.Tables[0].Rows[j]; HtmlTableRow newRow = new HtmlTableRow();
//newRow.Attributes.Add("bgColor", "#FFFFFF");
//newRow.Attributes.Add("onmousemove", "this.bgColor='#DDDDDD';");
//newRow.Attributes.Add("onmouseout", "this.bgColor='#FFFFFF';"); HtmlTableCell col_1 = new HtmlTableCell();
HtmlTableCell col_2 = new HtmlTableCell();
HtmlTableCell col_3 = new HtmlTableCell();
HtmlTableCell col_4 = new HtmlTableCell();
HtmlTableCell col_5 = new HtmlTableCell(); //文档标题
col_1.InnerHtml = curRow["caption"].ToString();
col_1.Style.Add(HtmlTextWriterStyle.TextAlign, "center"); //文档类型
string docType = curRow["docType"].ToString();
item = category.QueryCategoryById(docType);
col_2.InnerHtml = item.Tables[0].Rows[0]["cName"].ToString();
col_2.Style.Add(HtmlTextWriterStyle.TextAlign, "center"); //创建时间
col_3.InnerHtml = curRow["createTime"].ToString();
col_3.Style.Add(HtmlTextWriterStyle.TextAlign, "center"); //更新时间
col_4.InnerHtml = curRow["lastModifyTime"].ToString();
col_4.Style.Add(HtmlTextWriterStyle.TextAlign, "center"); //操作
col_5.InnerHtml = "[<a href='Document_View.aspx?id=" + curRow["id"].ToString() + "' target='_blank' style='color:blue;'>预览</a>]";
col_5.InnerHtml += " [<a href='Document_Update.aspx?id=" + curRow["id"].ToString() + "' target='_parent' style='color:blue;'>更新</a>]";
col_5.InnerHtml += " [<a href=\"javascript:deleteOneDoc($('#btnNull')," + curRow["id"] + ")\" id=" + curRow["id"] + " style='color:red;'>删除</a>]";
//<a href='javascript:deleteOneDoc("+item['id']+");' id="+ item['id']+ "> 取消申请 </a>
col_5.Style.Add(HtmlTextWriterStyle.TextAlign, "center"); newRow.Cells.Add(col_1);
newRow.Cells.Add(col_2);
newRow.Cells.Add(col_3);
newRow.Cells.Add(col_4);
newRow.Cells.Add(col_5); this.tbDocuments.Rows.Add(newRow);
}
SetControl();
} /// <summary>
/// 下一页
/// </summary>
private void NextPage()
{
if(PageIndex>=PageCount) return;
PageIndex++;
GetPage();
} /// <summary>
/// 上一页
/// </summary>
private void PrevPage()
{
if(PageIndex<2) return;
PageIndex--;
GetPage();
} protected void btnPrev_Click(object sender, ImageClickEventArgs e)
{
PrevPage();
}
protected void btnNext_Click(object sender, ImageClickEventArgs e)
{
NextPage();
}
}
public class B_Component
{
/// <summary>
/// 获取页面分页导航html
/// </summary>
/// <param name="bll">业务类</param>
/// <returns>html</returns>
public StringBuilder GetPageHtml(MB_RecordPage bll)
{
if (bll.DataCount % bll.PageSize == 0)
{
bll.PageCount = bll.DataCount / bll.PageSize;
}
else
{
bll.PageCount = bll.DataCount / bll.PageSize + 1;
}
StringBuilder sb = new StringBuilder();
if (bll.PageCount > 1 && bll.PageUrl != "")
{
if (bll.PageIndex < 1 || bll.PageIndex > bll.PageCount)
{
bll.PageIndex = 1;
}
sb.Append(@"
<div class=""pagenav"">
<div class="""">");
//<div class=""fl"">");
if (bll.PageIndex > 1)
{
sb.Append("<a href=" + bll.PageUrl + "&p=1>首页</a>");
}
else
{
sb.Append("<font color='#666666'>首页</font>");
}
if (bll.PageIndex > 1)
{
sb.Append(" <a href=" + bll.PageUrl + "&p=" + Convert.ToString(bll.PageIndex - 1) + ">上一页</a>");
}
else
{
sb.Append(" <font color='#666666'>上一页</font>");
} if (bll.PageCount > 1)
{
int beginNum = bll.PageIndex - 2;
if (beginNum > bll.PageCount - 4) beginNum = bll.PageCount - 4;
if (beginNum < 1) beginNum = 1;
int endNum = beginNum + 4;
if (endNum > bll.PageCount) endNum = bll.PageCount;
for (int i = beginNum; i <= endNum; i++)
{
if (i == bll.PageIndex)
{
sb.Append(" <font color='#666666'>" + i.ToString() + "</font>");
}
else
{
sb.Append(" <a href=" + bll.PageUrl + "&p=" + i.ToString() + ">" + i.ToString() + "</a>");
}
}
} if (bll.PageIndex < bll.PageCount)
{
sb.Append(" <a href=" + bll.PageUrl + "&p=" + Convert.ToString(bll.PageIndex + 1) + ">下一页</a>");
}
else
{
sb.Append(" <font color='#666666'>下一页</font>");
}
if (bll.PageIndex < bll.PageCount)
{
sb.Append(" <a href=" + bll.PageUrl + "&p=" + bll.PageCount.ToString() + ">尾页</a>");
}
else
{
sb.Append(" <font color='#666666'>尾页</font>");
}
sb.Append(" 共有<b>" + bll.DataCount + "</b>条记录,当前是第<b>" + bll.PageIndex + "</b>页/共<b>" + bll.PageCount + "</b>页。"); sb.Append(@"
</div>
<div class=""fr""></div>
<div class=""clear""></div>
</div>
");
return sb;
}
else
{
return sb;
}
}
}
///分页对象
public class MB_RecordPage
{
#region Model private string _tbname = "";
private string _fldname = "";
private Int32 _pagesize = 0;
private Int32 _pageindex = 0;
private string _strwhere = "";
private string _pageurl = "";
private int _pagecount = 0;
private Int32 _datacount = 0;
private string _strorder = "";
private string _strfieldshow = "";
private Int32 _startIndex = 0;
private Int32 _endIndex = 0; public MB_RecordPage()
{ }
public MB_RecordPage(Object currentPage)
{
if (currentPage != null && currentPage.ToString() != "")
{
try
{
_pageindex = Convert.ToInt16(currentPage);
}
catch
{
_pageindex = 1;
}
}
else
{
_pageindex = 1;
}
}
public void Init(Object currentPage)
{
if (currentPage != null && currentPage.ToString() != "")
{
try
{
_pageindex = Convert.ToInt16(currentPage);
}
catch
{
_pageindex = 1;
}
}
else
{
_pageindex = 1;
}
}
/// <summary>
/// 数据库表名称
/// </summary>
public string TbName
{
set { _tbname = value; }
get { return _tbname; }
} /// <summary>
/// 数据库表主键名称
/// </summary>
public string FldName
{
set { _fldname = value; }
get { return _fldname; }
} /// <summary>
/// 单页显示行数
/// </summary>
public Int32 PageSize
{
set { _pagesize = value; }
get { return _pagesize; }
} /// <summary>
/// 显示第几页
/// </summary>
public Int32 PageIndex
{
set { _pageindex = value; }
get { return _pageindex; }
} /// <summary>
/// 查询条件
/// </summary>
public string StrWhere
{
set { _strwhere = value; }
get { return _strwhere; }
} /// <summary>
/// 页面地址路径,包含参数。
/// </summary>
public string PageUrl
{
set { _pageurl = value; }
get { return _pageurl; }
} /// <summary>
/// 页合计数量
/// </summary>
public int PageCount
{
set { _pagecount = value; }
get { return _pagecount; }
} /// <summary>
/// 数据合计数量
/// </summary>
public Int32 DataCount
{
set { _datacount = value; }
get { return _datacount; }
} /// <summary>
/// 数据合计数量
/// </summary>
public string StrOrder
{
set { _strorder = value; }
get { return _strorder; }
} /// <summary>
/// 需要显示的字段,为空则所有的都显示
/// </summary>
public string StrFieldShow
{
set { _strfieldshow = value; }
get { return _strfieldshow; }
}
/// <summary>
/// 开始索引
/// </summary>
public Int32 StartIndex
{
get { return (this._pageindex - 1) * this._pagesize + 1; }
}
/// <summary>
///结束索引
/// </summary>
public Int32 EndIndex
{
get { return this._pageindex * this.PageSize > this._datacount ? this._datacount : this._pageindex * this.PageSize; }
}
#endregion
}调用的时候:
B_Component component = new B_Component();
MD_RecordPage recordPage = new MD_RecordPage();
recordPage.PageSize = 18;
if (Request["p"] != null && Request["p"].ToString() != "")
{
try
{
recordPage.PageIndex = Convert.ToInt16(Request["p"].ToString());
}
catch
{
recordPage.PageIndex = 1;
}
}
else
{
recordPage.PageIndex = 1;
}
recordPage.DataCount = bll.GetCount();
recordPage.PageUrl = "本页面";