All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
c#得到文件路径-多种不同格式_[Asp.Net教程]
.Net+MySQL组合开发(二),数据访问篇_[Asp.Net教程]
PHP中数组元素升序、降序及重新排序的函数_[PHP教程]
SQLServer2000启动1069错误_[SQL,Server教程]
.net生成静态页方法总结_[Asp.Net教程]
asp.net2.0网站基础之创建ASP.NET 2.0网站
ASP.NET技巧:用GZip压缩和解压_[Asp.Net教程]
实现基于php和MySQL的动态树型菜单_php资料_编程技术
推荐:ASP.NET虚拟主机安全漏洞解决方案_.net资料_编程技术
Sql,server,CLR自定义类型存储对象_[SQL,Server教程]
Reading number is top 10 pictures
两个妞在等世界上最短的火车
Average female college students2
The little woman's bright wire2
赵惟依写真2
No trading, no killing
Sora aoi on twitter1
Is said to be a Chinese female artist fame explicit pictures before2
Average female college students1
Absolutely shocked. National geographic 50 animal photographys4
The real super beauty1
Download software ranking
apache-tomcat-6.0.33
变速齿轮3.26
Tram sex maniac 2 (H) rar bag8
Visual C++界面编程技术
仙剑奇侠传98硬盘WINXP版
asp.net技术内幕
Sora aoi‘s film--Lust fan wall
Unix video tutorial15
Boxer vs Yellow1
Eclipse 4.2.2 For Win32
delv published in(发表于) 2014/1/6 9:03:59 Edit(编辑)
ASP.NET技巧:做个DataList,可分页的数据源_[Asp.Net教程]

ASP.NET技巧:做个DataList,可分页的数据源_[Asp.Net教程]

ASP.NET技巧:做个DataList 可分页的数据源_[Asp.Net教程]

这个数据源,分两部分,一是从数据类中调出数据,然后在本数据源中对分页参数以及页面分页辅助控件进行操作!在前面有三个控件控制翻页,一个下拉列表,两个LinkButton!

  下面 fill() 方法调用很简单,在页面中要重新绑定的地方 写上 fill() 就可以了,呵呵!但是一定要写哦,例如翻页动作执行后!


  下面是db类中的ds方法


public static DataTable ds(string que)
{//返回一个装载了SQL制定留言的数据表,
OleDbConnection con = odb.con();
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand=new OleDbCommand(que,con);
DataSet ds = new DataSet();
oda.Fill(ds,"thc");
return ds.Tables["thc"];
con.Close();
}下面方法使用的数据源就是上面的这个
private void fill()
{//做的一个方法,因为页内将有多次的绑定
//这里设置一个隐藏的Label,用与储存当前的页索引
int cup = Convert.ToInt32(pagelbl.Text);


PagedDataSource ps = new PagedDataSource();//NEW一个分页数据源
ps.DataSource = odb.ds("select * from guest order by id desc").DefaultView;//送一个SQL语句进去,确定该数据源的数据源,有点绕吧,呵呵
ps.AllowPaging = true;//允许分页
ps.PageSize = 2;//设置页的数量
ps.CurrentPageIndex = cup-1;
if (!IsPostBack)
{//判断页面是否第一次载入
for (int i = 1; i <= ps.PageCount; i++)
{//循环出页码
pageddl.Items.Add(i.ToString());
}
}
//下面主要是控制上下翻页按纽是否起用
pageup.Enabled = true;
pagedown.Enabled = true;
if (ps.IsFirstPage)
{//如果是最前页,上页按纽不可用
pageup.Enabled = false;
}
if (ps.IsLastPage)
{//如果是最后页,下页按纽不可用
pagedown.Enabled = false;
}
//设置页码下拉菜单当前选中的值
pageddl.SelectedItem.Text = cup.ToString();
//终于可以绑定给DataList了
DataList1.DataSource = ps;
DataList1.DataKeyField = "id";
DataList1.DataBind();
}


  再下面是翻页事件的处理


protected void pageddl_SelectedIndexChanged(object sender, EventArgs e)
{//页码下拉菜单事件
pagelbl.Text = pageddl.SelectedItem.Text.ToString();
fill();
}
protected void pagedown_Click(object sender, EventArgs e)
{//下页事件
pagelbl.Text = Convert.ToString(Convert.ToInt32(pagelbl.Text)+1);
fill();
}
protected void pageup_Click(object sender, EventArgs e)
{//上页事件
pagelbl.Text = Convert.ToString(Convert.ToInt32(pagelbl.Text)-1);
fill();
}


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.