{
SqlConnection conn = Class1.DBconnection();
if (Request.QueryString["Class_ID"] != "")
{
id = Request.QueryString["Class_ID"];
sql = "select n_ID,n_Big_ID,n_Title,n_Source,n_Content,n_Time from News where n_Big_ID=" + id + " order by n_ID desc";
}
else
{
sql = "select n_ID,n_Big_ID,n_Title,n_Source,n_Content,n_Time from News order by n_ID desc";
}
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["n_Title"].ToString().Length > 100)
{
ds.Tables[0].Rows[i]["n_Title"] = ds.Tables[0].Rows[i]["n_Title"].ToString().Substring(0, 100) + "...";
}
}
if (dt.Rows.Count > 0)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize =17;
int curPage;
if (Request.QueryString["page"] != null)
{
curPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage - 1;
this.Repeater1.DataSource = pds;
this.Repeater1.DataBind();
this.Label1.Text += "<a>共有<font color=red><b>" + ds.Tables[0].Rows.Count.ToString() + "</b></font>條記錄</a> ";
this.Label1.Text += "<a>每頁顯示<font color=red><b>" + pds.PageSize + "</b></font>條</a> ";
this.Label1.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>頁</a> ";
this.Label1.Text += "<a>當前第<font color=red><b>" + curPage.ToString() + "</b></font>頁</a> ";
if (curPage == 1)
{
this.Label1.Text += "<a>首頁</a> ";
this.Label1.Text += "<a>上一頁</a> ";
}
else
{
this.Label1.Text += "<a href='News_Manage.aspx?page=1&Class_ID=" + id + "'>首頁</a> ";
this.Label1.Text += "<a href='News_Manage.aspx?page=" + (curPage - 1).ToString() + "&Class_ID=" + id + "'>上一頁</a> ";
}
if (curPage == pds.PageCount)
{
this.Label1.Text += "<a>下一頁</a> ";
this.Label1.Text += "<a>尾頁</a> ";
}
else
{
this.Label1.Text += "<a href='News_Manage.aspx?page=" + (curPage + 1).ToString() + "&Class_ID=" + id + "'>下一頁</a> ";
this.Label1.Text += "<a href='News_Manage.aspx?page=" + pds.PageCount.ToString() + "&Class_ID=" + id + "'>尾頁</a> ";
}
string HtmlSelectString = "<select οnchange=\"javascript:window.location=this.value\">";
for (int i = 1; i <= pds.PageCount; i++)
{
if (i == curPage)
{
HtmlSelectString += "<option value=?page=" + i + "&Class_ID=" + id + " selected>第" + i + "頁</option>";
}
else
{
HtmlSelectString += "<option value=?page=" + i + "&Class_ID=" + id + ">第" + i + "頁</option>";
}
}
HtmlSelectString += "</select>";
this.Label1.Text += "<a>" + HtmlSelectString + "</a>";
}
else
{
this.Label1.Text = "當前沒有記錄";
}
ds.Dispose();
da.Dispose();
conn.Close();
}
效果如下: