久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

DataList控件實(shí)現(xiàn)分頁功能...

 蝸牛之窩 2009-11-14

DataList控件其實(shí)功能也很強(qiáng)大,,不過最令人頭疼的就是它不像GridView控件一樣內(nèi)置了分頁的功能,這么好的一個控件竟然不能分頁,,不過,,只是DataList沒有提供內(nèi)置的分頁功能,但是并不表示,,我們不能使用DataList控件來實(shí)現(xiàn)分頁,,既然它不給我分頁功能,那只好自己動手了,。

下面是全部原代碼,,這里用的是DataAdapterDataSet組合。


<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<Script Language="C#" Runat="Server">

OleDbConnection MyConn;
int PageSize,RecordCount,PageCount,CurrentPage;
public void Page_Load(Object src,EventArgs e)
{
 //
設(shè)定PageSize
 PageSize = 10;

 //連接語句
 string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(".")+"..\\DataBase\\db1.mdb;";
 MyConn = new OleDbConnection(MyConnString);
 MyConn.Open();

 //第一次請求執(zhí)行
 if(!Page.IsPostBack)
 {
  ListBind();
  CurrentPage = 0;
  ViewState["PageIndex"] = 0;

  //計(jì)算總共有多少記錄
  RecordCount = CalculateRecord();
  lblRecordCount.Text = RecordCount.ToString();

  //計(jì)算總共有多少頁
  PageCount = RecordCount/PageSize;
  lblPageCount.Text = PageCount.ToString();
  ViewState["PageCount"] = PageCount;
 }
}
//
計(jì)算總共有多少條記錄
public int CalculateRecord()
{
 int intCount;
 string strCount = "select count(*) as co from Score";
 OleDbCommand MyComm = new OleDbCommand(strCount,MyConn);
 OleDbDataReader dr = MyComm.ExecuteReader();
 if(dr.Read())
 {
  intCount = Int32.Parse(dr["co"].ToString());
 }
 else
 {
  intCount = 0;
 }
 dr.Close();
 return intCount;
}

ICollection CreateSource()
{

 int StartIndex;

 //設(shè)定導(dǎo)入的起終地址
 StartIndex = CurrentPage*PageSize;
 string strSel = "select * from Score";
 DataSet ds = new DataSet();

 OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel,MyConn);
 MyAdapter.Fill(ds,StartIndex,PageSize,"Score");

 return ds.Tables["Score"].DefaultView;
}
public void ListBind()
{
 score.DataSource = CreateSource();
 score.DataBind();

 lbnNextPage.Enabled = true;
 lbnPrevPage.Enabled = true;
 if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false;
 if(CurrentPage==0) lbnPrevPage.Enabled = false;
 lblCurrentPage.Text = (CurrentPage+1).ToString();

}

public void Page_OnClick(Object sender,CommandEventArgs e)
{
 CurrentPage = (int)ViewState["PageIndex"];
 PageCount = (int)ViewState["PageCount"];

 string cmd = e.CommandName;
 //
判斷cmd,,以判定翻頁方向
 switch(cmd)
 {
  case "next":
   if(CurrentPage<(PageCount-1)) CurrentPage++;
   break;
  case "prev":
   if(CurrentPage>0) CurrentPage--;
   break;
 }

 ViewState["PageIndex"] = CurrentPage;

 ListBind();

}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />條記錄 
當(dāng)前為<asp:Label id="lblCurrentPage" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" /> 

<asp:DataList id="score" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="yellow"
>
 <ItemTemplate>
  
姓名:<%# DataBinder.Eval(Container.DataItem,"Name") %>
  <asp:LinkButton id="btnSelect" Text="
編輯" CommandName="edit" runat="server" />
 </ItemTemplate>
</asp:DataList>
<asp:LinkButton id="lbnPrevPage" Text="
上一頁" CommandName="prev" OnCommand="Page_OnClick" runat="server" />
<asp:LinkButton id="lbnNextPage" Text="
下一頁" CommandName="next" OnCommand="Page_OnClick" runat="server" />

</form>
</body>
</html>

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多