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 Sequence Number in Grid Control with Paging

Polymorphism in C#

Print Function By JavaScript

Variable Value in Top Statement

How to Update Dependent Excel Cells Automatically

Auto Refresh .aspx page - ASP.NET