回覆列表
  • 1 # 午夜雨666

    using System;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;using System.Data.SqlClient;public partial class Demo : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){dlBind();}public void dlBind(){int curpage = Convert.ToInt32(lb_CurrentPage.Text);SqlConnection conn = new SqlConnection("server=.;database=db_MyData;uid=sa;pwd=");conn.Open();SqlDataAdapter da = new SqlDataAdapter("select top 50 * from tb_user", conn);DataSet ds = new DataSet();da.Fill(ds, "tb_user");PagedDataSource ps = new PagedDataSource();ps.DataSource = ds.Tables["tb_user"].DefaultView;ps.AllowPaging = true; //是否分頁ps.PageSize = 5; //顯示的數量ps.CurrentPageIndex = curpage - 1; //取得當前頁的頁碼if (!IsPostBack){for (int i = 1; i <= ps.PageCount; i++){DropDownList1.Items.Add(i.ToString());}DropDownList1.SelectedItem.Text = curpage.ToString();}LinkFirst.Enabled = true;LinkUp.Enabled = true;LinkDown.Enabled = true;LinkLast.Enabled = true;if (curpage == 1){LinkFirst.Enabled = false; //不顯示第一頁按鈕LinkUp.Enabled = false; //不顯示上一頁按鈕}if (curpage == ps.PageCount){LinkDown.Enabled = false; //不顯示下一頁按鈕LinkLast.Enabled = false; //不顯示最後一頁按鈕}lb_page.Text = Convert.ToString (ps.PageCount); //獲取總頁數lb_count .Text =ps .DataSourceCount .ToString (); //獲取記錄總數DataList1.DataSource = ps;DataList1.DataKeyField = "userLoginID";DataList1.DataBind();}protected void LinkFirst_Click(object sender, EventArgs e) //第一頁按鈕{lb_CurrentPage.Text = "1";dlBind();}protected void LinkUp_Click(object sender, EventArgs e) //上一頁按鈕{lb_CurrentPage.Text = Convert.ToString(Convert .ToInt32 (lb_CurrentPage .Text )-1);dlBind();}protected void LinkDown_Click(object sender, EventArgs e) //下一頁按鈕{lb_CurrentPage .Text =Convert .ToString (Convert .ToInt32 (lb_CurrentPage .Text) +1);dlBind ();}protected void LinkLast_Click(object sender, EventArgs e) //最後一頁按鈕{lb_CurrentPage.Text = lb_page.Text;dlBind();}protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) //跳轉到指定頁{int page = Convert.ToInt32(DropDownList1.SelectedItem.Value);lb_CurrentPage.Text = page.ToString();dlBind();}}

  • 中秋節和大豐收的關聯?
  • Ctrl+Alt+Insert是什麼?