Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hI,Friends i am want to add pages to data list iam write code like below but it is not working properly please help me...

my code is :
C#
protected void Page_Load(object sender, EventArgs e)
{
    ViewState["currentPage"]=0;
    
    
    if (!Page.IsPostBack)
    {          
    }

    databinddatalist();
}

private void Binddatalistgal()
{
    string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
   SqlDataAdapter dadapter = new SqlDataAdapter("SELECT Album2.AlbumID, Album2.DefaultPhotID, Album2.AlbumName,Album2.AlbumDescription, PhotAlbum.Photo FROM Album2 INNER JOIN PhotAlbum ON Album2.DefaultPhotID = PhotAlbum.PhotoID", constr);
   DataSet dset = new DataSet();
   adsource = new PagedDataSource();
   dadapter.Fill(dset);
   adsource.DataSource = dset.Tables[0].DefaultView;
   adsource.PageSize = 2;
   adsource.AllowPaging = true;
   adsource.CurrentPageIndex = Convert.ToInt32(ViewState["currentPage"]);
   dl_imgalbums.DataSource = adsource;
   dl_imgalbums.DataBind();
   lbnnext.Enabled = !adsource.IsLastPage;
   lbnprevious.Enabled = !adsource.IsFirstPage;
}

protected void lbnprevious_Click(object sender, EventArgs e)
{
    int currentPage = Convert.ToInt32(ViewState["currentPage"]);
    
    currentPage -= 1;
    
    ViewState["currentPage"] = currentPage;
    Binddatalistgal();
}
protected void lbnnext_Click(object sender, EventArgs e)
{
    int currentPage = Convert.ToInt32(ViewState["currentPage"]);
    
    currentPage += 1;
    
    ViewState["currentPage"] = currentPage;
    Binddatalistgal();  
}


when i am click in next link it will shows like
C#
"This webpage is not available"

so please help me.............
Posted
v2

1 solution

Refer below link, this will help you to implement Pagination for DataList control Implement Paging in DataList control in ASP.Net[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900