如何在asp.net中向datalisit添加页面 [英] how to add a pages to datalisit in asp.net

查看:86
本文介绍了如何在asp.net中向datalisit添加页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hI,朋友们我想将页面添加到数据列表中,我想写下面的代码,但它不能正常工作请帮帮我...



我的代码是:

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 :

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

"This webpage is not available"



所以请帮助我.............


so please help me.............

推荐答案

请参阅下面的链接,这将帮助您实现DataList控件的分页在ASP.Net中的DataList控件中实现分页 [ ^ ]
Refer below link, this will help you to implement Pagination for DataList control Implement Paging in DataList control in ASP.Net[^]


这篇关于如何在asp.net中向datalisit添加页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆