现在的位置: 首页 > 综合 > 正文

AspNetPager操作示例1

2012年09月01日 ⁄ 综合 ⁄ 共 3375字 ⁄ 字号 评论关闭

/// <summary>
    /// 用Sql语句填充GridView
    /// <param name="SQLStr">用户SQL语句</param>
    /// <param name="TableName">主表数据表名称</param>
    /// <param name="myGrid">目标GridView ID</param>
    /// <param name="myPager">目标AspNetPager ID</param>
    /// <param name="myPageSize">每页显示的记录数</param>
    /// <param name="ShowText">是否显示记录总数、页数信息</param>
    /// </summary>

public void BindGrid(string SQLStr, string TableName, Repeater myGrid, Wuqi.Webdiyer.AspNetPager myPager, int myPageSize, bool ShowText)
    {
        #region 绑定数据
        SqlDataAdapter da = new SqlDataAdapter(SQLStr, GetSQLConn());
        DataSet ds = new DataSet();
        myPager.PageSize = myPageSize;
        da.Fill(ds, myPager.PageSize * (myPager.CurrentPageIndex - 1), myPager.PageSize, TableName);
        myPager.AlwaysShow = true;
        myGrid.DataSource = ds;
        myGrid.DataBind();
        #endregion
    }

 

///////////////////

<asp:DataList ID="gvNewsList" runat="server" RepeatColumns="3"
                    RepeatDirection="Horizontal" Width="100%">
                    <ItemTemplate>
                        <table border="0" align="center" cellpadding="0" cellspacing="0">
                            <tr>
                              <td align="center"><a href="UpdateFile/<%#Eval("img") %>" target="_blank"><img src="UpdateFile/<%#Eval("img") %>" width="219" height="164" border="0" class="bkh" /></a></td>
                            </tr>
                            <tr>
                              <td align="center" class="hei12"><a href="Orther.aspx?id=<%#Eval("id") %>" class="hl12"><%#Eval("title") %></a></td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:DataList>

 

 

 

<webdiyer:AspNetPager ID="PostPager" runat="server" CustomInfoTextAlign="Right" Font-Names="宋体"
                                    HorizontalAlign="Left"
                     OnPageChanging="PostPager_PageChanging" PageSize="11"
                                    ShowBoxThreshold="2" ShowCustomInfoSection="Right" UrlPaging="True"
                                    Width="100%"
                                    FirstPageText="First" LastPageText="Last" NextPageText="Next"
                                    PageIndexBoxType="DropDownList" PrevPageText="Prev" ShowPageIndexBox="Always"
                                    SubmitButtonText="Go" TextAfterPageIndexBox="Page"
                                    TextBeforePageIndexBox="Go" ShowPageIndex="False"
                     CssClass="hl12"></webdiyer:AspNetPager>

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string type = "1";
            try
            {
                type = Request.QueryString["type"].ToString();
            }
            catch
            {
            }

 

            GridBind(type);
        }
    }

 protected void GridBind(string type)
    {
        lblTempID.Text = type;
        string SQLStr = "SELECT * FROM Orther WHERE (type = '" + type + "') AND (lei = '1') ORDER BY id DESC";

 

        DataTable dt = cls.GetDataTable(SQLStr);

        if (dt.Rows.Count > 0)
        {
            PostPager.RecordCount = dt.Rows.Count;
            cls.BindGrid(SQLStr, "netNews", gvNewsList, PostPager, 12, true);
        }
        else
        {
            lblMessage.Visible = true;
            PostPager.Visible = false;
            gvNewsList.Visible = false;
        }

        dt.Dispose();
    }
    protected void PostPager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        PostPager.CurrentPageIndex = e.NewPageIndex;
        GridBind(lblTempID.Text);
    }

抱歉!评论已关闭.