免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
ASP.NET 2.0 中AspNetPager.dll控件的分頁方法操作方法
大家好,我是Asp.net的忠實愛好者, 今天做項目時學會一種新控件[AspNetPager.dll]用法,很想把這方面的經(jīng)驗和大家分享一下,歡迎大家一起進來討論討論!
-------------------------------------------------------------------------
前臺顯示界面代碼Default.aspx[注意,代碼運行環(huán)境是VS.2005]

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>用AspNetPager.dll控件的分頁方法操作方法</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table border=1>
       <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
        <tr>
        <td><%#DataBinder.Eval(Container.DataItem,"job_id")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"job_desc")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"min_lvl")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"max_lvl")%></td>
        </tr>
        </ItemTemplate>
        </asp:Repeater>
    </table>
       <!--  <asp:DataGrid ID="DataGrid1" runat="server">
        </asp:DataGrid>-->
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="733px" FirstPageText="第一頁" LastPageText="最后一頁" NextPageText="下一頁" PrevPageText="上一頁" Font-Names="Arial" BackColor="#F8B500" AlwaysShow="true"  ShowInputBox="Always" SubmitButtonText="跳轉(zhuǎn)" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" >
              </webdiyer:AspNetPager>
    </div>
    </form>
</body>
</html>

 

//Default.aspx頁面的代碼

    DBAccess db = new DBAccess();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           BindGrid();
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindGrid();
    }

    public void BindGrid()
    {
        this.AspNetPager1.RecordCount = Int32.Parse(db.GetAllCount().ToString());
        int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
        int pageSize = this.AspNetPager1.PageSize =5;
        Repeater1.DataSource = db.GetCurrentPage(pageIndex, pageSize);
        Repeater1.DataBind();
    }

 

//前臺已經(jīng)OK了,就差后臺數(shù)據(jù)庫連接及分頁需要的方法,本項目數(shù)據(jù)庫示例為PUBS數(shù)據(jù)庫[安裝SQL SERVER就有的],分頁的表為jobs表

 

using System.Data.SqlClient;

 

public class DBAccess
{
    private SqlConnection con;
    private string DBName = "pubs";

    //創(chuàng)建連接對象并打開
    public void Open()
    {
        if (con == null)
            con = new SqlConnection("server=(local);uid=sa;pwd=sa;database="+DBName);
        if (con.State == ConnectionState.Closed)
            con.Open();
    }

    //創(chuàng)建一個命令對象并返回該對象
    public SqlCommand CreateCommand(string sqlStr)
    {
        Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = sqlStr;
        cmd.Connection = con;
        return cmd;
    }

    //生成一個對象并返回該結(jié)果集第一行第一列
    public object GetScalar(string sqlStr)
    {
        SqlCommand cmd = CreateCommand(sqlStr);
        object obj = cmd.ExecuteScalar();
        //CommadnBehavior.CloseConnection是將于DataReader的數(shù)據(jù)庫鏈接關(guān)聯(lián)起來  
        //當關(guān)閉DataReader對象時候也自動關(guān)閉鏈接
        return obj;
    }

     
    //執(zhí)行數(shù)據(jù)庫查詢并返回一個數(shù)據(jù)集 [當前頁碼,每頁記錄條數(shù)]
    public DataSet GetCurrentPage(int pageIndex, int pageSize)
    {
        //設置導入的起始地址
        int firstPage = pageIndex * pageSize;
        string sqlStr = "select * from jobs order by job_id desc";
        SqlCommand cmd = CreateCommand(sqlStr);
        DataSet dataset = new DataSet();
        SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
        dataAdapter.Fill(dataset,firstPage,pageSize,"jobs");
        cmd.Dispose();
        Close();
        dataAdapter.Dispose();
        return dataset;
    }

    //獲得查詢數(shù)據(jù)的總條數(shù)
    public object GetAllCount()
    {
        string sqlStr = "select count(*) from jobs";
        object obj = GetScalar(sqlStr);
        return obj;
    }
 
    //關(guān)閉數(shù)據(jù)庫
    public void Close()
    {
        if (con != null)
        {
            con.Close();
        }
    }

    //釋放資源
    public void Dispose()
    {
        if (con != null)
        {
            con.Dispose();
            con = null;
        }
    }

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Asp.net中DataGrid控件的自定義分頁
DataList控件實現(xiàn)分頁功能
分頁
簡單的ASP.NET無刷新分頁
ASPNETPAGER分頁控件的使用方法[圖文]
asp.net中分頁的幾種方法
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服