0

我正在尝试使用以下代码对我的数据列表使用分页...我能够在服务器端执行此操作,但我如何在客户端执行此操作..我的意思是我已经在页面加载时绑定了我的数据列表..alli 需要允许分页客户端

aspx

<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Previous" Text="<< Previous"
                            OnClick="Pager_Click"></asp:LinkButton>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <input id="Button6" type="button" value="close" onclick="Hidee2()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Next" Text="Next >>"
                            OnClick="Pager_Click"></asp:LinkButton>

笨蛋

private int CurrentPage = 1;
        private int ItemsPerPage = 4;


 protected void Page_Load(object sender, EventArgs e)
        {

int TotalRows = this.BindList(1);
                this.Prepare_Pager(TotalRows);
}



//this binds the datalist

 private int BindList(int PageNo)
        {
            int TotalRows = 0;
            DataTable dt = new DataTable();
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["DSN"]);
            SqlDataAdapter sda = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand("spx_Pager");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@PageNo", SqlDbType.Int).Value = PageNo;
            cmd.Parameters.Add("@ItemsPerPage", SqlDbType.Int).Value = ItemsPerPage;
            cmd.Parameters.Add("@TotalRows", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Connection = con;
            try
            {
                con.Open();
                sda.SelectCommand = cmd;
                sda.Fill(dt);
                DataList1.DataSource = dt;
                DataList2.DataSource = dt;
                DataList3.DataSource = dt;
                DataList4.DataSource = dt;

                DataList1.DataBind();
                DataList2.DataBind();
                DataList3.DataBind();
                DataList4.DataBind();
                TotalRows = Convert.ToInt32(cmd.Parameters["@TotalRows"].Value);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                con.Close();
                sda.Dispose();
                con.Dispose();
            }
            return TotalRows;
        }


//This prepaes pager for my datalist

        private void Prepare_Pager(int TotalRows)
        {
            int intPageCount = this.CalculateTotalPages(TotalRows);
            if (intPageCount > 1 && this.CurrentPage < intPageCount)
            {
                this.lnkNext.Enabled = true;
            }
            if (this.CurrentPage != 1)
            {
                this.lnkPrev.Enabled = true;
            }
            else
            {
                this.lnkPrev.Enabled = false;
            }
        }


//This is managing my pager click events for pervious and next link buttons above


protected void Pager_Click(object sender, EventArgs e)
        {
            LinkButton lnkPager = (LinkButton)sender;
            int PageNo = 1;
            switch (lnkPager.CommandName)
            {
                case "Previous":
                    PageNo = this.CurrentPage - 1;
                    break;
                case "Next":
                    PageNo = this.CurrentPage + 1;
                    break;
            }
            int TotalRows = this.BindList(PageNo);
            int PageCount = this.CalculateTotalPages(TotalRows);
            ViewState["CurrentPage"] = PageNo;
            if (PageNo == 1)
            {
                lnkPrev.Enabled = false;
            }
            else
            {
                lnkPrev.Enabled = true;
            }
            if (PageNo == PageCount)
            {
                lnkNext.Enabled = false;
            }
            else
            {
                lnkNext.Enabled = true;
            }
        }
4

1 回答 1

0

您可以使用 .netslackers DataControls ( http://dotnetslackers.com/projects/AjaxDataControls/ )

这些是纯客户端控件

于 2009-11-19T11:00:15.803 回答