private void ItemsGet() { string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); SqlConnection conn = new SqlConnection(strconn); SqlDataAdapter da = new SqlDataAdapter("select * from product", conn); DataSet ds = new DataSet(); da.Fill(ds, "product"); PagedDataSource objPds = new PagedDataSource(); objPds.DataSource = ds.Tables["product"].DefaultView; objPds.AllowPaging = true; objPds.PageSize = 3; objPds.CurrentPageIndex = CurrentPage; lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of " + objPds.PageCount.ToString(); cmdPrev.Enabled = !objPds.IsFirstPage; cmdNext.Enabled = !objPds.IsLastPage; DataList1.DataSource = objPds; DataList1.DataBind(); } public int CurrentPage { get { object o = this.ViewState["_CurrentPage"]; if (o == null) return 0; // default to showing the first page else return (int)o; } set { this.ViewState["_CurrentPage"] = value; } } protected void cmdPrev_Click(object sender, System.EventArgs e) { CurrentPage -= 1; ItemsGet(); } protected void cmdNext_Click(object sender, System.EventArgs e) { CurrentPage += 1; ItemsGet(); }
DataList1.DataSourceID = null; DataList1.DataSource = objPds; DataList1.DataBind();
DataList1.DataSource = null; DataList1.DataSource = objPds; DataList1.DataBind();
DataList1.DataSource = objPds.Table[0]; DataList1.DataBind();
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง