??
Sql
語句。很多情況下都是基于
Select Top
??
{0} *
??
From T_O_Log Where
??
Id Not in ( Select Top {1} Id From T_O_Log
??
Order By ID Desc ) Order By ID Desc
?? 其基本原理是獲取總數(shù) M 條記錄,而通過 m 條記錄獲取所需分頁的 n 條最前的記錄。 例如 分頁中每頁為 10 條記錄,現(xiàn)在要跳轉(zhuǎn)到 10 頁去。那么總要獲取的紀(jì)錄為 100 條,而我們所需要的其實是最后的 10 條記錄而已。所以前面的 90 條記錄拋棄。 為了實現(xiàn)的方便,該例子是用 aspnetpager 做為顯示頁碼和分頁轉(zhuǎn)向,當(dāng)然你也可以自己寫上一頁、下一頁的轉(zhuǎn)向工作
實現(xiàn)方法如下
<asp:DataGrid id="DataGrid1" runat="server" Width="100%" AutoGenerateColumns="False" singleValue="#F
</ asp:DataGrid>
第二步
雙擊該窗體,進入
codebehide
????????? { ?????????????? // 在此處放置用戶代碼以初始化頁面 ????????? ????? if (!Page.IsPostBack) ?????????????? { ??????????????????? GetLog(); ?????????????? } ????????? } private void GetLog() ????????? { ?????????????? string strsql; // 統(tǒng)計總的記錄數(shù)
??????????????
??????????????????? Conn.ConnectionString =@"server=MIS\PMSERVER;uid=sa;pwd=sa;database=test"; ??????????????????? Conn.Open(); ??????????????????? strsql=" Select count(ID) From T_O_Log"; ??????????????????? DataSet ds = new DataSet();
???????????????????
SqlDataAdapter Adp =
new
SqlDataAdapter(strSql,
??????????????????? Adp.Fill(ds,"TypeIdList"); ??????? ?????????????? this .AspNetPager1.RecordCount=System.Convert.ToInt32(ds.Tables[0].Rows[0][0]) ; ?????????????? BindData(); ????????? } private void BindData() ????????? { ?????????????? string strsql; ????????????? ?????????????? int RecordPage=(AspNetPager1.CurrentPageIndex-1)*AspNetPager1.PageSize; ????????? ????????? ??????????????
??????????????
??????????????????? Conn.ConnectionString =@"server=MIS\PMSERVER;uid=sa;pwd=sa;database=test"; ??????????????????? Conn.Open();
???????????????????
?????
strsql=String.Format(" Select Top
??
{0} *
??
From T_O_Log Where
??
Id Not in ( Select Top {1} Id From T_O_Log
??
Order By ID Desc) Order By ID Desc" ,AspNetPager1.PageSize.ToString(),RecordPage.ToString());
???????????????????
SqlDataAdapter Adp =
new
SqlDataAdapter(strSql,
??????????????????? Adp.Fill(ds,"TypeIdList"); ?????????????? this .DataGrid1.DataSource=ds.Tables["T_O_Log"]; ?????????????? this .DataGrid1.DataBind(); ??????????? ?????????????? // 動態(tài)設(shè)置用戶自定義文本內(nèi)容 ?????????????? adp.Dispose(); ????????????? ?????????????? AspNetPager1.CustomInfoText=" 記錄總數(shù): <font color=\"blue\"><b>"+AspNetPager1.RecordCount.ToString()+"</b></font>"; ?????????????? AspNetPager1.CustomInfoText+=" 總頁數(shù): <font color=\"blue\"><b>"+AspNetPager1.PageCount.ToString()+"</b></font>"; ?????????????? AspNetPager1.CustomInfoText+=" 當(dāng)前頁: <font color=\"red\"><b>"+AspNetPager1.CurrentPageIndex.ToString()+"</b></font>"; ????????? }
private void AspNetPager1_PageChanged( object src, Wuqi.Webdiyer.PageChangedEventArgs e) ????????? { ??????????? AspNetPager1.CurrentPageIndex=e.NewPageIndex; ?????????????? BindData(); ?????????????? System.Text.StringBuilder sb= new StringBuilder("<script Language=\"Javascript\"><!--\n");
?????????????? sb.Append("var el=document.all;"); ?????????????? sb.Append( this .DataGrid1.ClientID); ?????????????? sb.Append(".scrollIntoView(true);"); ?????????????? sb.Append("<"); ?????????????? sb.Append("/"); ?????????????? sb.Append("script>"); ?????????????? if (!Page.IsStartupScriptRegistered("scrollScript")) ??????????????????? Page.RegisterStartupScript("scrollScript",sb.ToString()); |
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
