Paged Data Source - Custom Paging

PagedDataSource, is a class that encapsulates the paging related properties for data-bound controls such as DataGrid, GridView, DataList, DetailsView and FormView that allow it to perform paging. And this article is going to combine both DataList control and PagedDataSource class to explain dynamic or custom paging methods for Asp.Net developers.
protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        if (!IsPostBack)
        {
            LoadPhoto();
        }
    }
    catch (Exception Exc)
    {
        HandleException = Exc;
    }
}

// LoadPhoto Function
private void LoadPhoto()
{
    PagedDataSource objPhotoPage = new PagedDataSource();
    objPhotoPage.AllowPaging = true;

    SOBLImageGallery _SOBLImageGallery = new SOBLImageGallery();
    DataSet dsImageGallery = _SOBLImageGallery.Select6Records(new SOENTImageGallery());


    if (dsImageGallery != null && dsImageGallery.Tables.Count > 0 && dsImageGallery.Tables[0].Rows.Count > 0)
    {
        objPhotoPage.DataSource = dsImageGallery.Tables[0].DefaultView;
        objPhotoPage.PageSize = 8;
        objPhotoPage.CurrentPageIndex = int.Parse(lblCurrentPhotoPage.Text) - 1;
        dlPhoto.DataSource = objPhotoPage;
        dlPhoto.DataBind();

        btnNextPhoto.Visible = !objPhotoPage.IsLastPage;
        btnPrevPhoto.Visible = !objPhotoPage.IsFirstPage;

    }
    else
    {
        dlPhoto.DataSource = null;
        dlPhoto.DataBind();
        btnNextPhoto.Visible = false;
        btnPrevPhoto.Visible = false;

    }
}                                                                                                                  

// Next button Click (btnNextPhoto_Click)

protected void btnNextPhoto_Click(object sender, EventArgs e)
{
    lblCurrentPhotoPage.Text = Convert.ToString(int.Parse(lblCurrentPhotoPage.Text) + 1);
    LoadPhoto();
}

// Previous button Click (btnPrevPhoto_Click)

protected void btnPrevPhoto_Click(object sender, EventArgs e)
{
    lblCurrentPhotoPage.Text = Convert.ToString(int.Parse(lblCurrentPhotoPage.Text) - 1);
    LoadPhoto();
}

Comments

Popular posts from this blog

Auto Refresh .aspx page - ASP.NET

Auto Sequence Number in Grid Control with Paging

MVC Request Execution Stages - Life Cycle

LINQ - C# Programming

ASP.NET MVC Version History

How to Edit More than 200 Rows in SQL Server 2008

Page get postback twice in Mozilla!!!!

SOLID Principles with C#

How to Update Dependent Excel Cells Automatically