关于asp.net分页
来源:互联网 发布:round robin调度算法 编辑:程序博客网 时间:2024/05/16 13:51
private void list_bind()
{
SqlConnection conn = Class1.DBconnection();
if (Request.QueryString["Class_ID"] != "")
{
id = Request.QueryString["Class_ID"];
sql = "select n_ID,n_Big_ID,n_Title,n_Source,n_Content,n_Time from News where n_Big_ID=" + id + " order by n_ID desc";
}
else
{
sql = "select n_ID,n_Big_ID,n_Title,n_Source,n_Content,n_Time from News order by n_ID desc";
}
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["n_Title"].ToString().Length > 100)
{
ds.Tables[0].Rows[i]["n_Title"] = ds.Tables[0].Rows[i]["n_Title"].ToString().Substring(0, 100) + "...";
}
}
if (dt.Rows.Count > 0)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize =17;
int curPage;
if (Request.QueryString["page"] != null)
{
curPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage - 1;
this.Repeater1.DataSource = pds;
this.Repeater1.DataBind();
this.Label1.Text += "<a>共有<font color=red><b>" + ds.Tables[0].Rows.Count.ToString() + "</b></font>条记录</a> ";
this.Label1.Text += "<a>每页显示<font color=red><b>" + pds.PageSize + "</b></font>条</a> ";
this.Label1.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>页</a> ";
this.Label1.Text += "<a>当前第<font color=red><b>" + curPage.ToString() + "</b></font>页</a> ";
if (curPage == 1)
{
this.Label1.Text += "<a>首页</a> ";
this.Label1.Text += "<a>上一页</a> ";
}
else
{
this.Label1.Text += "<a href='News_Manage.aspx?page=1&Class_ID=" + id + "'>首页</a> ";
this.Label1.Text += "<a href='News_Manage.aspx?page=" + (curPage - 1).ToString() + "&Class_ID=" + id + "'>上一页</a> ";
}
if (curPage == pds.PageCount)
{
this.Label1.Text += "<a>下一页</a> ";
this.Label1.Text += "<a>尾页</a> ";
}
else
{
this.Label1.Text += "<a href='News_Manage.aspx?page=" + (curPage + 1).ToString() + "&Class_ID=" + id + "'>下一页</a> ";
this.Label1.Text += "<a href='News_Manage.aspx?page=" + pds.PageCount.ToString() + "&Class_ID=" + id + "'>尾页</a> ";
}
string HtmlSelectString = "<select onchange=\"javascript:window.location=this.value\">";
for (int i = 1; i <= pds.PageCount; i++)
{
if (i == curPage)
{
HtmlSelectString += "<option value=?page=" + i + "&Class_ID=" + id + " selected>第" + i + "页</option>";
}
else
{
HtmlSelectString += "<option value=?page=" + i + "&Class_ID=" + id + ">第" + i + "页</option>";
}
}
HtmlSelectString += "</select>";
this.Label1.Text += "<a>" + HtmlSelectString + "</a>";
}
else
{
this.Label1.Text = "当前没有记录";
}
ds.Dispose();
da.Dispose();
{
SqlConnection conn = Class1.DBconnection();
if (Request.QueryString["Class_ID"] != "")
{
id = Request.QueryString["Class_ID"];
sql = "select n_ID,n_Big_ID,n_Title,n_Source,n_Content,n_Time from News where n_Big_ID=" + id + " order by n_ID desc";
}
else
{
sql = "select n_ID,n_Big_ID,n_Title,n_Source,n_Content,n_Time from News order by n_ID desc";
}
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["n_Title"].ToString().Length > 100)
{
ds.Tables[0].Rows[i]["n_Title"] = ds.Tables[0].Rows[i]["n_Title"].ToString().Substring(0, 100) + "...";
}
}
if (dt.Rows.Count > 0)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize =17;
int curPage;
if (Request.QueryString["page"] != null)
{
curPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage - 1;
this.Repeater1.DataSource = pds;
this.Repeater1.DataBind();
this.Label1.Text += "<a>共有<font color=red><b>" + ds.Tables[0].Rows.Count.ToString() + "</b></font>条记录</a> ";
this.Label1.Text += "<a>每页显示<font color=red><b>" + pds.PageSize + "</b></font>条</a> ";
this.Label1.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>页</a> ";
this.Label1.Text += "<a>当前第<font color=red><b>" + curPage.ToString() + "</b></font>页</a> ";
if (curPage == 1)
{
this.Label1.Text += "<a>首页</a> ";
this.Label1.Text += "<a>上一页</a> ";
}
else
{
this.Label1.Text += "<a href='News_Manage.aspx?page=1&Class_ID=" + id + "'>首页</a> ";
this.Label1.Text += "<a href='News_Manage.aspx?page=" + (curPage - 1).ToString() + "&Class_ID=" + id + "'>上一页</a> ";
}
if (curPage == pds.PageCount)
{
this.Label1.Text += "<a>下一页</a> ";
this.Label1.Text += "<a>尾页</a> ";
}
else
{
this.Label1.Text += "<a href='News_Manage.aspx?page=" + (curPage + 1).ToString() + "&Class_ID=" + id + "'>下一页</a> ";
this.Label1.Text += "<a href='News_Manage.aspx?page=" + pds.PageCount.ToString() + "&Class_ID=" + id + "'>尾页</a> ";
}
string HtmlSelectString = "<select onchange=\"javascript:window.location=this.value\">";
for (int i = 1; i <= pds.PageCount; i++)
{
if (i == curPage)
{
HtmlSelectString += "<option value=?page=" + i + "&Class_ID=" + id + " selected>第" + i + "页</option>";
}
else
{
HtmlSelectString += "<option value=?page=" + i + "&Class_ID=" + id + ">第" + i + "页</option>";
}
}
HtmlSelectString += "</select>";
this.Label1.Text += "<a>" + HtmlSelectString + "</a>";
}
else
{
this.Label1.Text = "当前没有记录";
}
ds.Dispose();
da.Dispose();
conn.Close();
}
效果如下:
- 关于asp.net分页
- 关于asp.net分页技术实现
- 关于 ASP.net + JQGrid 的分页
- AJAX 分页 asp.net分页
- asp.net关于分页上的数据删除问题
- ASP.NET关于分页上的数据删除问题
- ASP.NET关于ListView与DataPager后台绑定数据源分页
- ASP.NET手工分页
- asp.net分页
- 【asp.NET】分页实例
- ASP.NET分页程序
- asp.net分页
- ASP.NET中的分页
- ASP.NET分页
- ASP.NET中的分页
- ASP.NET简单分页
- asp.net分页(二)
- asp.net分页功能
- 关于二次函数的求根
- 最新伤感情侣日志发布:用微笑去掩饰自己内心的伤悲
- VC点评:下一个伟大的社交网络在哪里?
- CentOS 6安装MySQL及phpMyAdmin
- 帮忙改正
- 关于asp.net分页
- 部分Android App带有严重的SSL漏洞
- CodeForces round146
- 分段函数求值
- 排序算法
- Objective-C基础教程四(Foundation Kit)
- 环境搭建
- redis环境搭建——介绍、安装、配置
- How to stream video to your android phone 如何将视频远程传输至你的android手机?