repeater分页实例

上传人:s9****2 文档编号:468520464 上传时间:2022-11-06 格式:DOC 页数:4 大小:39.50KB
返回 下载 相关 举报
repeater分页实例_第1页
第1页 / 共4页
repeater分页实例_第2页
第2页 / 共4页
repeater分页实例_第3页
第3页 / 共4页
repeater分页实例_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《repeater分页实例》由会员分享,可在线阅读,更多相关《repeater分页实例(4页珍藏版)》请在金锄头文库上搜索。

1、repeater分页实例using System;using System.Data;using System.Data.SqlClient;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 p

2、artial class repeate : System.Web.UI.Pageprotected void Page_Load(object sender, EventArgs e)if (!IsPostBack)Repeater1.DataSource = pds();Repeater1.DataBind(); private PagedDataSource pds()string connstring = ConfigurationManager.ConnectionStringspconn.ConnectionString;SqlConnection con = new SqlCon

3、nection(connstring);DataSet ds = new DataSet();SqlDataAdapter sda = new SqlDataAdapter(select * from authors,con);sda.Fill(ds,name);SqlDataAdapter sda2 = new SqlDataAdapter(select * from titleauthor,con);sda2.Fill(ds,title);ds.Relations.Add(myrela,ds.Tablesname.Columnsau_id,ds.Tablestitle.Columnsau_

4、id);PagedDataSource pds = new PagedDataSource();pds.DataSource = ds.Tablesname.DefaultView;pds.AllowPaging = true;/允许分页pds.PageSize = 5;/单页显示项数pds.CurrentPageIndex = Convert.ToInt32(Request.QueryStringpage);return pds;protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)if (

5、e.Item.ItemType = ListItemType.Footer)DropDownList ddlp = (DropDownList)e.Item.FindControl(ddlp);HyperLink lpfirst = (HyperLink)e.Item.FindControl(hlfir);HyperLink lpprev = (HyperLink)e.Item.FindControl(hlp);HyperLink lpnext = (HyperLink)e.Item.FindControl(hln);HyperLink lplast = (HyperLink)e.Item.F

6、indControl(hlla);pds().CurrentPageIndex = ddlp.SelectedIndex;int n = Convert.ToInt32(pds().PageCount);/n为分页数int i = Convert.ToInt32(pds().CurrentPageIndex);/i为当前页Label lblpc = (Label)e.Item.FindControl(lblpc);lblpc.Text = n.ToString();Label lblp = (Label)e.Item.FindControl(lblp);lblp.Text = Convert.

7、ToString(pds().CurrentPageIndex + 1);if (!IsPostBack)for (int j = 0; j n; j+)ddlp.Items.Add(Convert.ToString(j + 1);if (i = n - 1)lpfirst.Enabled = true;lplast.Enabled = false;lpnext.Enabled = false;lpprev.Enabled = true;elselpnext.NavigateUrl = ?page= + (i + 1);lpfirst.NavigateUrl = ?page=0;/向本页传递参

8、数pagelplast.NavigateUrl = ?page= + (n - 1);ddlp.SelectedIndex = Convert.ToInt32(pds().CurrentPageIndex);/更新下拉列表框中的当前选中页序号protected void ddlp_SelectedIndexChanged(object sender, EventArgs e)/脚模板中的下拉列表框更改时激发string pg=Convert.ToString(Convert.ToInt32(DropDownList)sender).SelectedValue)-1);/获取列表框当前选中项Response.Redirect(repeate.aspx?page=+pg);/页面转向/repeate.aspx无标题页作者书籍a href=repeate.aspx?id=asp:Repeater ID=Repeater2 runat=server DataSource= 共页 当前为第页跳至第页 女包、名牌包、背包:|冬装新款、流行冬装、今年流行秋冬装:

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号