[新闻系统]自定义分页控件(针对MS SQL数据库)

参考了MSDN的分页控件  他写的太麻烦也用不到那么多东西,对于这个新闻系统来讲也没必要做那么麻烦
参考地址:http://www.microsoft.com/china/msdn/archives/library/dnaspp/html/PagerControls.asp

针对MS SQL数据库 采用SQL语句查询

下载https://files.cnblogs.com/zhzkl/Control.rar
代码贴出来
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Data;

namespace zhzklControls
{
    
/// <summary>
    
/// WebCustomControl1 的摘要说明。
    
/// </summary>

    [DefaultProperty("Text"),
        ToolboxData(
"<{0}:ControlTest runat=server></{0}:ControlTest>")]
    
public class ControlTest : System.Web.UI.WebControls.WebControl , INamingContainer
    
{
        
public class PageChangedEventArgs : EventArgs
        
{
            
public int OldPageIndex;
            
public int NewPageIndex;
        }

        
        
private string text;
        
private Control _controlToPaginate = null;
        
private string QueryPageCommandText = "SELECT * FROM " + 
            
"(SELECT TOP {0} * FROM " + 
            
"(SELECT TOP {1} * FROM ({2}) AS t0 ORDER BY {3} {4}) AS t1 " + 
            
"ORDER BY {3} {5}) AS t2 " + 
            
"ORDER BY {3}";
        
private string QueryCountCommandText = "SELECT COUNT(*) FROM ({0}) AS t0";

        
Programme Interface

        
UserInterface

        
HelpMethod 

        
private void first_Click(object sender, EventArgs e)
        
{
            GoToPage(
0);
        }

        
private void prev_Click(object sender, EventArgs e)
        
{
            GoToPage(
this.CurrentPageIndex - 1);
        }


        
private void next_Click(object sender, EventArgs e)
        
{
            GoToPage(
this.CurrentPageIndex + 1);
        }


        
private void last_Click(object sender, EventArgs e)
        
{
            GoToPage(
this.TotalPages - 1);
        }


        
protected override void CreateChildControls()
        
{
            Controls.Clear();
            ClearChildViewState();

            BuildUI();
        }


        
/// <summary>
        
/// 将此控件呈现给指定的输出参数。    
        
/// </summary>
        
/// <param name="output"> 要写出到的 HTML 编写器 </param>

        protected override void Render(HtmlTextWriter output)
        
{
            
if (Site != null && Site.DesignMode) 
                CreateChildControls();            
            
            
base.Render(output);
        }


        
private void dpPageIndex_SelectedIndexChanged(object sender, EventArgs e)
        
{
            DropDownList pageList 
= (DropDownList) sender;
            
int pageIndex = Convert.ToInt32(pageList.SelectedItem.Value);
            GoToPage(pageIndex);
        }

    }

}

posted on 2006-02-09 17:47  xwang  阅读(786)  评论(1编辑  收藏  举报

导航