木头象

人生如棋局

导航

带搜索的分页控件之二

2,简单设计器
/********************************************************************
 *  FileName : pagefootdesign.cs
 * Target  : 翻页控件设计器
 * Author  : Baihao
 * CreateDate : 2003/04/17    10:22
 * LastModify : 2003/04/17    10:22
 * History  : 
     2003/04/17 10:22 创建
*********************************************************************/

using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;

namespace EII.Lib.WebControls.Design
{
 /// <summary>
 /// PageFootDesign 的摘要说明。
 /// </summary>
 public class PageFootDesign: System.Web.UI.Design.ControlDesigner
 {

  public override string GetDesignTimeHtml()
  {
   // Component is the control instance, defined in the base
   // designer
   
   PageFoot page = (PageFoot ) Component;

   if (page.CurrentPage  != "" && page.CurrentPage != null )
   {
    StringWriter sw = new StringWriter();
    HtmlTextWriter tw = new HtmlTextWriter(sw);

    HyperLink placeholderLink = new HyperLink();

    // put control text into the link's Text
    placeholderLink.Text = page.CurrentPage ;
    placeholderLink.NavigateUrl = page.CurrentPage ;
    placeholderLink.RenderControl(tw);


    
    //placeholderLink.NavigateUrl = show.Width;
    placeholderLink.RenderControl(tw);

    return sw.ToString();
   }
   else
    return GetEmptyDesignTimeHtml();
  }
 }
}

3, 使用方法
a:aspx


<%@ Register TagPrefix="Wonders" Namespace="EII.Lib.WebControls" Assembly="EII.Lib" %>
...
<TR>
 <TD align="center"><Wonders:PAGEFOOT id="WFoot" runat="server"></Wonders:PAGEFOOT></TD>
</TR>
...
b : .cs
  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!this.IsPostBack )
   {

  try
    {
     nPage   = Convert.ToInt32(Request[WFoot.PageIndex]);
    }
    catch
    {
     nPage   = 1;
    }
    
   //自定义业务层,请修改
    Department dept = new Department();
   
    DataSet ds   = dept.QueryAllDeptByID(DeptID);

    if(ds != null && (ds.Tables.Count >0))
    {
     this.Datagrid1.DataSource = ds.Tables[0].DefaultView;
     int nRowCount = ds.Tables[0].Rows.Count ;

   

     nPage = WFoot.Show(nPage,PAGE_SIZE,nRowCount);
     Datagrid1.CurrentPageIndex = nPage - 1;
     Datagrid1.DataBind();

    }
    

    
   }

4, 例图
<img src="http://class.naea.edu.cn/Images/pagefoot.jpg">

posted on 2004-02-17 10:57  木头象  阅读(994)  评论(1编辑  收藏  举报