locked
Paging in DatsList RRS feed

  • Question

  • User-169979396 posted
    Hi,
    I have this code for Data List Paging, its good but I want display the pahing in other format , like this format:
    http://www.google.com/search?q=asp.net&hl=ar&biw=1366&bih=559&tbm=isch&prmd=ivnsb&ei=NWQxTvacOMejmQWg_qHICQ&sa=N&start=18&ndsp=18 
    Please I want the paging like that format.
    So what I shall change in my code?
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
    
                ItemsGet();
    
            }
    
        }
    
        private void ItemsGet()
        {
    
            //// Read sample item info from XML document into a DataSet
    
            //DataSet Items = new DataSet();
    
            //Items.ReadXml(MapPath("Items.xml"));
    
            // Populate the repeater control with the Items DataSet
    
            PagedDataSource objPds = new PagedDataSource();
    
            //objPds.DataSource = Items.Tables[0].DefaultView;
    
            DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    
    
    
            objPds.DataSource = dv;
    
            objPds.AllowPaging = true;
    
            objPds.PageSize = 1;
    
            objPds.CurrentPageIndex = CurrentPage;
    
            lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
    
            + objPds.PageCount.ToString();
    
            // Disable Prev or Next buttons if necessary
    
            cmdPrev.Enabled = !objPds.IsFirstPage;
    
            cmdNext.Enabled = !objPds.IsLastPage;
    
            DataList1.DataSource = objPds;
    
            DataList1.DataBind();
    
        }
    
    
    
        public int CurrentPage
        {
    
            get
            {
    
                // look for current page in ViewState
    
                object o = this.ViewState["_CurrentPage"];
    
                if (o == null)
    
                    return 0; // default to showing the first page
    
                else
    
                    return (int)o;
    
            }
    
            set
            {
    
                this.ViewState["_CurrentPage"] = value;
    
            }
    
        }
    
        protected void cmdPrev_Click(object sender, System.EventArgs e)
        {
    
            // Set viewstate variable to the previous page
    
            CurrentPage -= 1;
    
            // Reload control
    
            ItemsGet();
    
        }
    
        protected void cmdNext_Click(object sender, System.EventArgs e)
        {
    
            // Set viewstate variable to the next page
    
            CurrentPage += 1;
    
            // Reload control
    
            ItemsGet();
    
        }
    Thursday, July 28, 2011 9:37 AM

Answers

All replies