eswar rao

eswar rao

  • 1.6k
  • 98
  • 19.1k

how to add a pages to datalisit in asp.net

Dec 23 2015 1:42 AM
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 :
<pre lang="C#">protected void Page_Load(object sender, EventArgs e)
{
ViewState[&quot;currentPage&quot;]=0;
if (!Page.IsPostBack)
{
}
databinddatalist();</pre>
}
<pre lang="C#">private void Binddatalistgal()
{</pre><pre lang="C#">string constr = ConfigurationManager.ConnectionStrings[&quot;ConnectionString&quot;].ConnectionString;
SqlDataAdapter dadapter = new SqlDataAdapter(&quot;SELECT Album2.AlbumID, Album2.DefaultPhotID, Album2.AlbumName,Album2.AlbumDescription, PhotAlbum.Photo FROM Album2 INNER JOIN PhotAlbum ON Album2.DefaultPhotID = PhotAlbum.PhotoID&quot;, 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[&quot;currentPage&quot;]);
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[&quot;currentPage&quot;]);
currentPage -= 1;
ViewState[&quot;currentPage&quot;] = currentPage;
Binddatalistgal();
}
protected void lbnnext_Click(object sender, EventArgs e)
{
int currentPage = Convert.ToInt32(ViewState[&quot;currentPage&quot;]);
currentPage += 1;
ViewState[&quot;currentPage&quot;] = currentPage;
Binddatalistgal();
}</pre>
when i am click in next link it will shows like <pre lang="C#">"This webpage is not available"</pre>
so please help me.............

Answers (3)