开发者

paging in datalist using javascript

iam trying to use paging for my datalist using following code...iam able to do it server side but how can i do it client side..i mean iam already binding my datalist on page load..alli need is to allow paging on client side

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>

coodebhind

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.Da开发者_运维技巧taBind();
                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;
            }
        }


You could use .netslackers DataControls (http://dotnetslackers.com/projects/AjaxDataControls/)

These are pure Client Side Controls

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜