谢谢帖出代码!ASPX文件和存储过程代码都帖出,我是初学!

解决方案 »

  1.   

    http://dev.csdn.net/develop/article/33/33643.shtm
      

  2.   

    代码页:
    namespace test6
    {
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Text;
    using System.Text.RegularExpressions; /// <summary>
    /// Members_admin 的摘要说明。
    /// </summary>
    public class Members_admin : System.Web.UI.UserControl
    {
    protected System.Web.UI.WebControls.DataGrid DG_Report; public StringBuilder Footer
    {
    get
    {
    int CurrentPage = Convert.ToInt32(Request.QueryString["Page"]); int RecordsPerPage = 10; DataOperate dp = new DataOperate("CnStr");
    dp.DataOperSqlStr = "select count(*) from region";    //用到其他页面需修改此处表名
    int TotalRecords = Convert.ToInt32(dp.SelectScalar());
    int TotalPages = TotalRecords/RecordsPerPage;
    if(TotalPages < 1)
    TotalPages = 1;
    else
    TotalPages += 1;

    ////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    ///绑定到DataGrid
    ///
        ///              用到其他页面需修改此处sql语句
    dp.DataOperSqlStr = "SELECT top "+RecordsPerPage+" * from region "+
    "where regionID not in (select top "+(CurrentPage-1)*RecordsPerPage+" regionID from region order by regionID desc)order by regionID desc";
    DG_Report.DataSource = dp.SelectDT("members").DefaultView;
    DG_Report.DataBind();    ////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    ///总记录数,当前是页数,首页,上一页,下一页,末页
    ///
    StringBuilder PageFoot = new StringBuilder();
    PageFoot.Append("共" +TotalRecords+"条记录&nbsp;");
    PageFoot.Append("第" +CurrentPage+"/"+TotalPages+"页&nbsp;");

    string AbsUrl;//URL?左边的部分
    AbsUrl = this.Context.Request.Url.ToString();
    if(AbsUrl.IndexOf("?") == -1)
    {     }
    else
    {
    AbsUrl = AbsUrl.Substring(0,AbsUrl.IndexOf("?"));
    } if(CurrentPage <= 1)
    {
    CurrentPage = 1;
    PageFoot.Append("<a href='"+AbsUrl+"?Page=2'>下一页</a>&nbsp;");
    PageFoot.Append("<a href='"+AbsUrl+"?Page="+TotalPages.ToString()+"'>末页</a>&nbsp;");
    }
    else if(CurrentPage >= TotalPages)
    {
    int LPage = TotalPages -1;
    PageFoot.Append("<a href='"+AbsUrl+"?Page=1'>首页</a>&nbsp;");
    PageFoot.Append("<a href='"+AbsUrl+"?Page="+LPage.ToString()+"'>上一页</a>&nbsp;");
    }
    else
    {
    PageFoot.Append("<a href='"+AbsUrl+"?Page=1'>首页</a>&nbsp;");
    int LPage = CurrentPage - 1;
    PageFoot.Append("<a href='"+AbsUrl+"?Page="+LPage.ToString()+"'>上一页</a>&nbsp;");
    int NPage = CurrentPage + 1;
    PageFoot.Append("<a href='"+AbsUrl+"?Page="+NPage.ToString()+"'>下一页</a>&nbsp;");
    PageFoot.Append("<a href='"+AbsUrl+"?Page="+TotalPages.ToString()+"'>末页</a>&nbsp;");
    } ////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    ///跳转部分
    ///
    PageFoot.Append("跳转到");
    PageFoot.Append("<INPUT id='Go_Text' style='WIDTH: 40px; HEIGHT: 22px' type='text' size='1' value='"+CurrentPage+"'>");
    PageFoot.Append("页&nbsp;");

    PageFoot.Append("<IMG src='../images/go.gif' onmouseover=style.cursor="+"'hand' onclick ='go(Go_Text,"+TotalPages+")' >"); PageFoot.Append("<script language='javascript'>\n");
    PageFoot.Append(" function go(ctrl,max)\n" );
    PageFoot.Append("         {\n" );
    PageFoot.Append("             if(ctrl.value >= 1 && ctrl.value <= max)\n" );
    PageFoot.Append("             {\n" );
    PageFoot.Append("                 var url;\n" );
    PageFoot.Append("                 var index;\n" );
    PageFoot.Append("                 url = location.href;\n" );
    PageFoot.Append("                 index = url.indexOf('?');\n" );
    PageFoot.Append("                 if(index == -1)\n" );
    PageFoot.Append("                 {\n" );
    PageFoot.Append("                 }\n" );
    PageFoot.Append("                 else\n" );
    PageFoot.Append("                 {\n" );
    PageFoot.Append("                     url = url.substring(0,index);\n" );
    PageFoot.Append("                 }\n" );
    PageFoot.Append("                 location.href = url + '?Page=' + ctrl.value;\n" );
    PageFoot.Append("             }\n" );
    PageFoot.Append("                 else\n" );
    PageFoot.Append("               {\n" );
    PageFoot.Append("               alert('您输入的页码必须是符合页面要求的数字,最大值是:' + max);\n" );
    PageFoot.Append("               return false;\n" );
    PageFoot.Append("               }\n" );
    PageFoot.Append("         }\n" );
    PageFoot.Append("</script>\n");
    //////////////////////////////////////////////////////////////////////////////////////////////// return PageFoot;
    }
    } private void Page_Load(object sender, System.EventArgs e)
    {
    this.DataBind();
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }
      

  3.   

    Members_admin.ascx :
    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="Members_admin.ascx.cs" Inherits="test6.Members_admin" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    <FONT face="宋体">
    <table cellSpacing="0" cellPadding="0" width="100%" border="0">
    <TBODY>
    <tr>
    <td><asp:datagrid id="DG_Report" AllowPaging="false" PageSize="15" Width="100%" runat="server">
    <AlternatingItemStyle BackColor="WhiteSmoke"></AlternatingItemStyle>
    <HeaderStyle BackColor="#CCCCCC"></HeaderStyle>
    <PagerStyle Visible="False"></PagerStyle>
    </asp:datagrid>
    </FONT></TD></TR>
    <TR>
    <TD align="right"><%# Footer %>
    </TD>
    </TR>
    </TBODY></TABLE></FONT>
      

  4.   

    以上是我在用户控件里写的分页,用的是Sql代码,没用存储过程,希望对你有帮助,存储过程的网上不少,你可以查一下!我上面的分页185万条记录,很快!
      

  5.   

    我的这个你看看
    http://blog.csdn.net/ericfine/archive/2004/09/09/99302.aspx
    刚写好的:)是SQL的,命令很简单
      

  6.   

    唉,你的数据库是MDB,让我怎么用啊
      

  7.   

    给你一个
    狠快的速度
    存储过程
    CREATE PROCEDURE GetRecordFromPage
        @tblName      varchar(255),       -- 表名
        @fldName      varchar(255),       -- 字段名
        @PageSize     int = 10,           -- 页尺寸
        @PageIndex    int = 1,            -- 页码
        @IsCount      bit = 0,            -- 返回记录总数, 非 0 值则返回
        @OrderType    bit = 0,            -- 设置排序类型, 非 0 值则降序
        @strWhere     varchar(1000) = ''  -- 查询条件 (注意: 不要加 where)
    ASdeclare  @strSQL   varchar(1000)     -- 主语句
    declare @strTmp   varchar(300)     -- 临时变量
    declare @strOrder varchar(400)       -- 排序类型if @OrderType != 0
    begin
        set @strTmp = "<(select min"
        set @strOrder = " order by [" + @fldName +"] desc"
    end
    else
    begin
        set @strTmp = ">(select max"
        set @strOrder = " order by [" + @fldName +"] asc"
    endset @strSQL = "select top " + str(@PageSize) + " * from ["
        + @tblName + "] where [" + @fldName + "]" + @strTmp + "(["
        + @fldName + "]) from (select top " + str((@PageIndex-1)*@PageSize) + " ["
        + @fldName + "] from [" + @tblName + "]" + @strOrder + ") as tblTmp)"
        + @strOrderif @strWhere != ''
        set @strSQL = "select top " + str(@PageSize) + " * from ["
            + @tblName + "] where [" + @fldName + "]" + @strTmp + "(["
            + @fldName + "]) from (select top " + str((@PageIndex-1)*@PageSize) + " ["
            + @fldName + "] from [" + @tblName + "] where (" + @strWhere + ") "
            + @strOrder + ") as tblTmp) and (" + @strWhere + ") " + @strOrderif @PageIndex = 1
    begin
        set @strTmp = ""
        if @strWhere != ''
            set @strTmp = " where (" + @strWhere + ")"    set @strSQL = "select top " + str(@PageSize) + " * from ["
            + @tblName + "]" + @strTmp + " " + @strOrder
    endif @IsCount != 0
        set @strSQL = "select count(*) as Total from [" + @tblName + "]"exec (@strSQL)
    GO<%@ Page language="c#" Codebehind="QueryUser.aspx.cs" AutoEventWireup="false" Inherits="ShopWeb.QueryUser" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>QueryUser</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <table cellSpacing="0" cellPadding="0" width="776" border="1">
    <tr>
    <td align="center" colSpan="6">
    <div align="center"><FONT face="宋体">Query User</FONT></div>
    </td>
    </tr>
    <tr>
    <td style="WIDTH: 21px; HEIGHT: 23px"><asp:dropdownlist id="DropDownList2" runat="server" Width="120px"></asp:dropdownlist></td>
    <td style="WIDTH: 64px; HEIGHT: 23px"><FONT face="宋体">KeyWords</FONT></td>
    <td style="WIDTH: 137px; HEIGHT: 23px">&nbsp;
    <asp:textbox id="TextBox2" runat="server"></asp:textbox></td>
    <td style="WIDTH: 54px; HEIGHT: 23px"><asp:button id="Button4" runat="server" Text="Button"></asp:button></td>
    <td style="WIDTH: 53px; HEIGHT: 23px"><asp:button id="Button5" runat="server" Text="Button"></asp:button></td>
    <td style="WIDTH: 591px; HEIGHT: 23px"><asp:button id="Button6" runat="server" Text="Button"></asp:button></td>
    </tr>
    <tr>
    <td colSpan="6"><asp:datagrid id="DataGridOrder" runat="server" Width="100%"></asp:datagrid></td>
    </tr>
    <tr>
    <td style="HEIGHT: 22px" colSpan="6"><asp:linkbutton id="btnFirst" runat="server" CommandArgument="First">First</asp:linkbutton>&nbsp;&nbsp;&nbsp;
    <asp:linkbutton id="btnPre" runat="server" CommandArgument="Pre">Pre</asp:linkbutton><FONT face="宋体">&nbsp;
    <asp:linkbutton id="btnNext" runat="server" CommandArgument="Next">Next</asp:linkbutton></FONT><FONT face="Times New Roman">&nbsp;
    <asp:LinkButton id="btnLast" runat="server" CommandArgument="Last">Last</asp:LinkButton></FONT><FONT face="宋体">&nbsp;&nbsp;
    <asp:Label id="txtCurrentPage" runat="server" Width="32px">Label</asp:Label>/
    <asp:Label id="txtAllpage" runat="server">Label</asp:Label></FONT></td>
    </tr>
    <tr>
    <td colSpan="6">&nbsp;</td>
    </tr>
    </table>
    <asp:Button id="Button7" runat="server" Text="Button"></asp:Button></form>
    </body>
    </HTML>
      

  8.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Configuration;
     namespace ShopWeb
    {
    /// <summary>
    /// QueryUser 的摘要说明。
    /// </summary>
    public class QueryUser : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DropDownList DropDownList1;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.Button Button2;
    protected System.Web.UI.WebControls.Button Button3;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected System.Web.UI.WebControls.DropDownList DropDownList2;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.Button Button4;
    protected System.Web.UI.WebControls.Button Button5;
    protected System.Web.UI.WebControls.Button Button6;
    protected System.Web.UI.WebControls.LinkButton btnFirst;
    protected System.Web.UI.WebControls.LinkButton btnPre;
    protected System.Web.UI.WebControls.LinkButton btnNext;
    protected System.Web.UI.WebControls.DataGrid DataGridOrder;
    protected System.Web.UI.WebControls.LinkButton btnLast;
    protected System.Web.UI.WebControls.Label txtCurrentPage;
    protected System.Web.UI.WebControls.Label txtAllpage;
    protected System.Web.UI.WebControls.Button Button7;
    protected System.Web.UI.WebControls.DropDownList drownlistQueryType;

    #region 函数
     
    private int ComputerRecordCount()
    {
     
    string MyConnectionString=ConfigurationSettings.AppSettings["ConnectionString1"];
    SqlConnection MyConnection=new SqlConnection(MyConnectionString);
    SqlCommand Cmd=new SqlCommand("select Count(OrderID) from Orders",MyConnection) ;
    MyConnection.Open();

    SqlDataReader Dr=Cmd.ExecuteReader(); if(Dr.Read())
    {
    return Dr.GetInt32(0);
    }
    else
    {
    return 0;
    }


    }
    private int ComputerPageCount()
    {
    int RecordCount=0;
    int YuShu=0;
    string MyConnectionString=ConfigurationSettings.AppSettings["ConnectionString1"];
    SqlConnection MyConnection=new SqlConnection(MyConnectionString);
    SqlCommand Cmd=new SqlCommand("select Count(OrderID) from Orders",MyConnection) ;
    MyConnection.Open();

    SqlDataReader Dr=Cmd.ExecuteReader();
    if(Dr.Read())
    {
    RecordCount=Dr.GetInt32(0);
    }
    MyConnection.Close(); 
    YuShu=RecordCount%10; if(YuShu==0)
    {
    return RecordCount/10; }
    else
    {
    return RecordCount/10+1;
    } }
    private void DataBindDataGird(int PageNumber)
    {
    string MyConnectionString=ConfigurationSettings.AppSettings["ConnectionString1"];
    SqlConnection MyConnection=new SqlConnection(MyConnectionString);
    SqlDataAdapter  Da=new SqlDataAdapter();
    SqlCommand Cmd=new SqlCommand();
    Cmd.Connection=MyConnection;
    Cmd.CommandType=CommandType.StoredProcedure;
    Cmd.CommandText="[GetRecordFromPage]";
    Cmd.Parameters.Add("@tblName","Orders");
    Cmd.Parameters.Add("@fldName","OrderID");
    Cmd.Parameters.Add("@PageIndex",PageNumber);
    Cmd.Parameters.Add("@PageSize",10);
    Cmd.Parameters.Add("@strWhere","");

    Da.SelectCommand=Cmd; DataSet ds=new DataSet();
    Da.Fill(ds,"Orders");
    Response.Write(ds.Tables[0].Rows.Count);
    DataGridOrder.DataSource=ds.Tables[0].DefaultView;
    Cache["ds"]=ds.Tables[0].DefaultView; DataGridOrder.DataBind();
    int CurrentPage=int.Parse(ViewState["CurrentPage"].ToString());
    int PageCount=int.Parse(ViewState["PageCout"].ToString());
    this.btnFirst.Enabled=true;
    this.btnPre.Enabled=true;
    this.btnNext.Enabled=true;
    this.btnLast.Enabled=true;
    if(CurrentPage<=1)
    {
     
    this.btnFirst.Enabled=false;
    this.btnPre.Enabled=false; }
    if(CurrentPage>=PageCount)
    {
     
    this.btnLast.Enabled=false;
    this.btnNext.Enabled=false;
    } }
    #endregion
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!Page.IsPostBack)
    {
    ViewState["PageCout"]=ComputerPageCount(); 
    ViewState["CurrentPage"]=1;
    DataBindDataGird(1);
    this.txtCurrentPage.Text="1";
    this.txtAllpage.Text= ViewState["PageCout"].ToString();
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.btnFirst.Command += new System.Web.UI.WebControls.CommandEventHandler(this.ChangePage);
    this.btnPre.Command += new System.Web.UI.WebControls.CommandEventHandler(this.ChangePage);
    this.btnNext.Command += new System.Web.UI.WebControls.CommandEventHandler(this.ChangePage);
    this.btnLast.Command += new System.Web.UI.WebControls.CommandEventHandler(this.ChangePage);
    this.Button7.Click += new System.EventHandler(this.Button7_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion  
    private void ChangePage(object sender, System.Web.UI.WebControls.CommandEventArgs e)
    {
    int PageCount= int.Parse(ViewState["PageCout"].ToString());
    string Change=e.CommandArgument.ToString();
    int CurrentPage=int.Parse(ViewState["CurrentPage"].ToString());
    if(Change=="Pre")
    {
     
    if(CurrentPage<=1)
    {
    ViewState["CurrentPage"]=1; }
    else
    {
    ViewState["CurrentPage"]=CurrentPage-1; }
    }
    else if(Change=="Next")
    {
     
    if(CurrentPage>=PageCount)
    {
    ViewState["CurrentPage"]=PageCount; }
    else
    {
    ViewState["CurrentPage"]=CurrentPage+1; } }
    else if(Change=="First")
    {
    ViewState["CurrentPage"]=1; }
    else if(Change=="Last")
    {
    ViewState["CurrentPage"]=PageCount;
    }
    this.txtCurrentPage.Text=ViewState["CurrentPage"].ToString();
    DataBindDataGird(int.Parse(ViewState["CurrentPage"].ToString()));
    } private void Button7_Click(object sender, System.EventArgs e)
    {
    // this.OutputExcel((DefaultView)Cache["ds"],"ss");
    }
    }
    }
      

  9.   

    请问数据是SQL2000自带的,还是要我自己设计,