Repeter实现分页显示,嵌套

Repeter实现分页显示,嵌套
using System; using System.Data; using System.Configuration; 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; using System.Data.SqlClient; publicpartialclass _Default : System.Web.UI.Page {     protectedvoid Page_Load(object sender, EventArgs e)     {         if (!IsPostBack)         {              Repeater1.DataSource = pds();              Repeater1.DataBind();          }          ds.Relations.Add("mydb", ds.Tables["name"].Columns["au_id"], ds.Tables["title"].Columns["au_id"]);      }     public PagedDataSource pds()     {         string connstring = ConfigurationManager.ConnectionStrings["pubconn"].ConnectionString;          SqlConnection con =new SqlConnection(connstring);          SqlDataAdapter sda =new SqlDataAdapter("select * from authors", con);          DataSet ds =new DataSet();          sda.Fill(ds, "name");          SqlDataAdapter sda2 =new SqlDataAdapter("select * from titleauthor", con);          sda2.Fill(ds, "title");          ds.Relations.Add("mydb", ds.Tables["name"].Columns["au_id"], ds.Tables["title"].Columns["au_id"]);          PagedDataSource pds =new PagedDataSource();          pds.DataSource =ds.Tables["name"].DefaultView;          pds.AllowPaging =true;          pds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);          pds.PageSize =5;         return pds;      }     protectedvoid Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)     {         if (e.Item.ItemType == ListItemType.Footer)         {             int n = pds().PageCount;             int i = pds().CurrentPageIndex;              Label gjy = (Label)e.Item.FindControl("gjy");              gjy.Text = n.ToString();              Label djy = (Label)e.Item.FindControl("djy");              djy.Text = Convert.ToString(pds().CurrentPageIndex+1);              HyperLink first = (HyperLink)e.Item.FindControl("first");              first.NavigateUrl ="?page=0";              HyperLink end = (HyperLink)e.Item.FindControl("end");              end.NavigateUrl ="?page="+ Convert.ToInt32(n -1);              HyperLink p = (HyperLink)e.Item.FindControl("p");              HyperLink next = (HyperLink)e.Item.FindControl("next");             if (i <=0)             {                  first.Enabled =false;                  p.Enabled =false;                  next.Enabled =true;              }             else             {                  p.NavigateUrl ="?page="+ Convert.ToInt32(i -1);              }             if (i > n -2)             {                  end.Enabled =false;                  next.Enabled =false;                  p.Enabled =true;              }             else             {                  next.NavigateUrl ="?page="+ Convert.ToInt32(i +1);              }          }      } }
 

posted on 2009-08-14 10:06  xieguang133  阅读(181)  评论(0)    收藏  举报

导航