AspNetPage分页





<asp:GridView ID="gv_citylist" runat="server" AutoGenerateColumns="False" Width="100%"
                BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
                CellPadding="4" GridLines="Horizontal">
                <RowStyle BackColor="White" ForeColor="#333333" HorizontalAlign="Center" />
                <Columns>
                    <asp:TemplateField HeaderText="活动标题">
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("c_c_title") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="活动内容">
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("c_c_content") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="活动时间">
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Eval("c_c_time","{0:yyyy-MM-dd}") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="活动地点">
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Eval("c_c_address") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                </Columns>
                <FooterStyle BackColor="White" ForeColor="#333333" />
                <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
            </asp:GridView>
            <webdiyer:AspNetPager ID="AspNetPagerclub" CssClass="paginator" CurrentPageButtonClass="cpb"
                runat="server" AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页"
                PageSize="20" PrevPageText="上一页" ShowCustomInfoSection="Left" ShowInputBox="Never"
                OnPageChanged="AspNetPagerclub_PageChanged" CustomInfoTextAlign="Left" LayoutType="Table"
                EnableUrlRewriting="false" UrlRewritePattern="~/Url_Page{0}.html" SubmitButtonClass="SubmitBtn"
                SubmitButtonText="转到" PageIndexBoxClass="PageIndexBox" ShowPageIndexBox="Never"
                HorizontalAlign="Right">
            </webdiyer:AspNetPager>



调用存储过程


public static DataTable PageView(string tbname, string FieldKey, int PageCurrent, int PageSize, string FieldShow, string Where, string FieldOrder, ref int RecordCount)
    {
        SqlParameter[] parms = new SqlParameter[]
        {
            new SqlParameter("@tbname",SqlDbType.VarChar),
            new SqlParameter("@FieldKey",SqlDbType.VarChar,1000),
            new SqlParameter("@PageCurrent",SqlDbType.Int),
            new SqlParameter("@PageSize",SqlDbType.Int),
            new SqlParameter("@FieldShow",SqlDbType.VarChar,1000),
            new SqlParameter("@Where",SqlDbType.VarChar,1000),
            new SqlParameter("@FieldOrder",SqlDbType.VarChar,1000),
            new SqlParameter("@PageCount",SqlDbType.Int),
            new SqlParameter("@RecordCount",SqlDbType.Int),


        };
        parms[0].Value = tbname;
        parms[1].Value = FieldKey;
        parms[2].Value = PageCurrent;
        parms[3].Value = PageSize;
        parms[4].Value = FieldShow;
        parms[5].Value = Where;
        parms[6].Value = FieldOrder;
        parms[7].Direction = ParameterDirection.Output;
        parms[8].Direction = ParameterDirection.Output;


        DataTable dt = new DataTable();
        SQLHelper.FillDataTablePage("PageView", dt, parms);
        RecordCount = Convert.ToInt32(parms[8].Value);
        return dt;


    }


    /// <summary>
    /// 执行一个SQL查询,填充DataTable
    /// </summary>
    /// <param name="cmdText"></param>
    /// <param name="dt"></param>
    /// <param name="cmdParms"></param>
    public static void FillDataTablePage(string cmdText, DataTable dt, params SqlParameter[] cmdParms)
    {
        SqlCommand cmd = new SqlCommand();

        using (SqlConnection conn = new SqlConnection(CONN_STRING))
        {

            PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, cmdText, cmdParms);
            SqlDataAdapter ada = new SqlDataAdapter(cmd);
            ada.Fill(dt);
            ada.Dispose();
        }
    }




int RecordCount;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Initial();
        }
    }

    protected void Initial()
    {
        DataTable dt = PageDAL.PageView("club_city", "c_c_id", this.AspNetPagerclub.CurrentPageIndex, this.AspNetPagerclub.PageSize, "*", "", "", ref RecordCount);
        this.AspNetPagerclub.RecordCount = RecordCount;

        this.AspNetPagerclub.CustomInfoHTML = string.Format("当前第{0}/{1}页 共{2}条记录 每页{3}条", new object[] { this.AspNetPagerclub.CurrentPageIndex, this.AspNetPagerclub.PageCount, this.AspNetPagerclub.RecordCount, this.AspNetPagerclub.PageSize });

        if (dt.Rows.Count == 0)
        {
            dt.Rows.Add(dt.NewRow());
            this.gv_citylist.DataSource = dt;
            this.gv_citylist.DataBind();

            int columnCount = dt.Columns.Count;
            gv_citylist.Rows[0].Cells.Clear();
            gv_citylist.Rows[0].Cells.Add(new TableCell());
            gv_citylist.Rows[0].Cells[0].ColumnSpan = columnCount;
            gv_citylist.Rows[0].Cells[0].Text = "没有符合条件的数据!";
            gv_citylist.Rows[0].Cells[0].Style.Add("text-align", "left");
            gv_citylist.Rows[0].Cells[0].Style.Add("color", "red");

        }
        else
        {
           

            this.gv_citylist.DataSource = dt;
            this.gv_citylist.DataBind();
        }
    }


    protected void AspNetPagerclub_PageChanged(object sender, EventArgs e)
    {
        Initial();

    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值