国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.net url分頁的用戶控件

2024-07-10 12:55:12
字體:
來源:轉載
供稿:網友
最近做一個相冊程序頻繁的需要分頁,所以就想寫一個用戶控件出來。
  
  代碼如下:
  
  autopage.ascx頁面
  
  <%@ control language="c#" autoeventwireup="false" codebehind="autopage.ascx.cs" inherits="album.autopage" targetschema="http://schemas.microsoft.com/intellisense/ie5" %>
  <table border="0" cellpadding="0" cellspacing="0">
   <tr>
   <td valign="middle" height="30">共<asp:label id="lb_itemcount" forecolor="red" runat="server"></asp:label>條記錄 </td>
   <td valign="middle" height="30"><asp:hyperlink id="hpl_first" runat="server">首頁</asp:hyperlink> </td>
   <td valign="middle" height="30"><asp:hyperlink id="hpl_prev" runat="server">上頁</asp:hyperlink> </td>
   <td valign="middle" height="30">當前<asp:label id="lb_currentpage" runat="server"></asp:label>頁/共<asp:label id="lb_pagecount" runat="server"></asp:label>頁 </td>
   <td valign="middle" height="30"><asp:hyperlink id="hpl_next" runat="server">下頁</asp:hyperlink> </td>
   <td valign="middle" height="30"><asp:hyperlink id="hpl_last" runat="server">末頁</asp:hyperlink> </td>
   <td valign="middle" height="30"><asp:textbox id="txb_page" runat="server" width="32px" borderstyle="solid" borderwidth="1px"
   bordercolor="silver"></asp:textbox></td>
   <td valign="middle" height="30"><asp:imagebutton id="btn_go" runat="server" imageurl="album_images/go.gif"></asp:imagebutton></td>
   <td valign="middle" height="30"><asp:label id="lb_url" runat="server" visible="false"></asp:label><asp:label id="lb_params" runat="server" visible="false"></asp:label></td>
   </tr>
  </table>
  
  autopage.ascx.cs頁面
  
  namespace album
  {
   using system;
   using system.data;
   using system.drawing;
   using system.web;
   using system.web.ui.webcontrols;
   using system.web.ui.htmlcontrols;
   using system.data.sqlclient;
  
   /// <summary>
   /// uc 的摘要說明。
   /// </summary>
   public class autopage : system.web.ui.usercontrol
   {
   protected system.web.ui.webcontrols.hyperlink hpl_first;
   protected system.web.ui.webcontrols.hyperlink hpl_prev;
   protected system.web.ui.webcontrols.hyperlink hpl_next;
   protected system.web.ui.webcontrols.label lb_currentpage;
   protected system.web.ui.webcontrols.label lb_pagecount;
   protected system.web.ui.webcontrols.hyperlink hpl_last;
   public int pagesize;
   public string pagep;
   protected system.web.ui.webcontrols.textbox txb_page;
   protected system.web.ui.webcontrols.label lb_url;
   protected system.web.ui.webcontrols.label lb_itemcount;
   public string url;
   protected system.web.ui.webcontrols.label lb_params;
   protected system.web.ui.webcontrols.imagebutton btn_go;
   public string params;
  
   private void page_load(object sender, system.eventargs e)
   {
  
   }
  
   public pageddatasource databind(datatable dt)
   {
   lb_url.text = url;
   lb_params.text = params;
   //創建分頁類
   pageddatasource objpage = new pageddatasource();
   //設置數據源
   objpage.datasource = dt.defaultview;
   //允許分頁
   objpage.allowpaging = true;
   //設置每頁顯示的項數
   objpage.pagesize = pagesize;
   //設置當前頁的索引
   int curpage=1;
   try
   {
   curpage = convert.toint32(pagep);
   if (curpage<1 curpage>objpage.pagecount)
   {
   response.redirect(url+"?page=1"+params);
   }
   }
   catch
   {
   response.redirect(url+"?page=1"+params);
   }
   objpage.currentpageindex = curpage-1;
   //顯示狀態信息
   lb_itemcount.text = dt.rows.count.tostring();
   lb_currentpage.text = curpage.tostring();
   lb_pagecount.text =objpage.pagecount.tostring();
  
   //如果當前頁面不是首頁
   if (!objpage.isfirstpage)
   {
   hpl_prev.navigateurl=url + "?page=" + convert.tostring(curpage-1)+params;
   hpl_first.navigateurl=url + "?page=1"+params;
   }
   //如果當前頁面不是最后一頁
   if (!objpage.islastpage)
   {
   hpl_next.navigateurl=url+ "?page=" + convert.tostring(curpage+1)+params;
   hpl_last.navigateurl=url + "?page=" +objpage.pagecount.tostring()+params;
   }
   return objpage;
   }
  
  
   #region web 窗體設計器生成的代碼
   override protected void oninit(eventargs e)
   {
   //
   // codegen: 該調用是 asp.net web 窗體設計器所必需的。
   //
   initializecomponent();
   base.oninit(e);
   }
  
   /// <summary>
   /// 設計器支持所需的方法 - 不要使用代碼編輯器
   /// 修改此方法的內容。
   /// </summary>
   private void initializecomponent()
   {
   this.btn_go.click += new system.web.ui.imageclickeventhandler(this.btn_go_click);
   this.load += new system.eventhandler(this.page_load);
  
   }
   #endregion
  
   private void btn_go_click(object sender, system.web.ui.imageclickeventargs e)
   {
   response.redirect(lb_url.text+"?page="+txb_page.text+lb_params.text);
   }
  
  
   }
  }
  
  調用的時候需要設置幾個參數pagesize(每頁顯示數據個數),pagep(傳遞的分頁參數),parmp(其他的request.qureystring參數),url(頁面地址)
  
  綁定的時候只需要把控件的datasource=autopage1.databind(datatable變量)

商業源碼熱門下載www.html.org.cn

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 墨脱县| 建阳市| 渝北区| 吴川市| 双牌县| 江油市| 登封市| 沽源县| 雷州市| 嵊泗县| 临颍县| 红原县| 张家川| 井冈山市| 三穗县| 沙湾县| 武威市| 尖扎县| 镇雄县| 筠连县| 岐山县| 夏津县| 鹤峰县| 建平县| 黔西县| 兴和县| 合川市| 扶风县| 伊宁市| 拜泉县| 安阳市| 台州市| 偏关县| 湘潭市| 常州市| 金秀| 永福县| 吉林省| 青阳县| 盐亭县| 叶城县|