资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
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 partial 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 SqlConnection(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_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 (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.FindControl(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.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;/向本页传递参数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= 共页 当前为第页跳至第页 女包、名牌包、背包:www.naitiao.com|冬装新款、流行冬装、今年流行秋冬装:dongzhuang.qqxk.net
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号