WPF DataGrid的分页实现
原理:其实分页功能的实现大家都清楚,无非就是把一个记录集通过运算来刷选里面对应页码的记录。
接来下我们再次添加新的代码
- <Grid>
- <DataGrid Name="dataGrid1" AutoGenerateColumns="False">
- <!--省略N个代码-->
- </DataGrid>
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="转到" Margin="5"/>
- <TextBox Name="tbxPageNum" Text="" />
- <TextBlock Text="页" />
- <Button Content="GO" Click="btnGo_Click"/>
- <Button Name="btnUp" Content="上一页" VerticalAlignment="Center" Click="btnUp_Click"/>
- <Button Name="btnNext" Content="下一页" VerticalAlignment="Center" Click="btnNext_Click"/>
- <TextBlock Height="20">
- <TextBlock Text="【共" />
- <TextBlock Name="tbkTotal" Foreground="Red" />
- <TextBlock Text="页】" />
- <TextBlock Text="【当前" />
- <TextBlock Name="tbkCurrentsize" Foreground="Red" />
- <TextBlock Text="页】" />
- </TextBlock>
- </StackPanel>
- </Grid>
首先我们先写个分页的方法,供上面这些事件调用
后台代码
- //number表示每个页面显示的记录数 currentSize表示当前显示页数
- private void Binding(int number, int currentSize)
- {
- List<Information> infoList = new List<Information>();
- infoList = tbInfo.GetInformationList(); //获取数据源
- int count = infoList.Count; //获取记录总数
- int pageSize = 0; //pageSize表示总页数
- if (count % number == 0)
- {
- pageSize = count / number;
- }
- else
- {
- pageSize = count / number + 1;
- }
- tbkTotal.Text = pageSize.ToString();
- tbkCurrentsize.Text = currentSize.ToString();
- infoList = infoList.Take(number * currentSize).Skip(number * (currentSize - 1)).ToList(); //刷选第currentSize页要显示的记录集
- dataGrid1.ItemsSource = infoList; //重新绑定dataGrid1
- }
- //分页方法写好了 接下来就是响应下一页,上一页,和跳转页面的事件了
- //先定义一个常量
- const int Num=12; //表示每页显示12条记录
- //上一页事件
- private void btnUp_Click(object sender, RoutedEventArgs e)
- {
- int currentsize = int.Parse(tbkCurrentsize.Text); //获取当前页数
- if (currentsize > 1)
- {
- Binding(Num, currentsize - 1); //调用分页方法
- }
- }
- //下一页事件
- private void btnNext_Click(object sender, RoutedEventArgs e)
- {
- int total = int.Parse(tbkTotal.Text); //总页数
- int currentsize = int.Parse(tbkCurrentsize.Text); //当前页数
- if (currentsize < total)
- {
- Binding(Num, currentsize + 1); //调用分页方法
- }
- }
- //跳转事件
- private void btnGo_Click(object sender, RoutedEventArgs e)
- {
- int pageNum = int.Parse(tbxPageNum.Text);
- int total = int.Parse(tbkTotal.Text); //总页数
- if (pageNum >= 1 && pageNum <= total)
- {
- Binding(Num, pageNum); //调用分页方法
- }
- }
- 原文参考 http://blog.csdn.net/sanjiawan/article/details/6785394#
WPF DataGrid的分页实现的更多相关文章
- WPF DataGrid实现分页显示
主要代码如下 /// <summary> /// 读取指定页面的数据 /// </summary> /// <param name="pagePerCount& ...
- WPF DataGrid常用属性记录
WPF DataGrid常用属性记录 组件常用方法: BeginEdit:使DataGrid进入编辑状态. CancelEdit:取消DataGrid的编辑状态. CollapseRowGroup:闭 ...
- WPF DATAGRID - COMMITTING CHANGES CELL-BY-CELL
In my recent codeproject article on the DataGrid I described a number of techniques for handling the ...
- SSh结合Easyui实现Datagrid的分页显示
近日学习Easyui,发现非常好用,界面很美观.将学习的心得在此写下,这篇博客写SSh结合Easyui实现Datagrid的分页显示,其他的例如添加.修改.删除.批量删除等功能将在后面的博客一一写来. ...
- WPF DataGrid某列使用多绑定后该列排序失效,列上加入 SortMemberPath 设置即可.
WPF DataGrid某列使用多绑定后该列排序失效 2011-07-14 10:59hdongq | 浏览 1031 次 悬赏:20 在wpf的datagrid中某一列使用了多绑定,但是该列排序失 ...
- xceed wpf datagrid
<!--*********************************************************************************** Extended ...
- 关于Jquery EasyUI中的DataGrid服务器端分页随记
一.关于DataGrid的分页和排序参数 对于分页参数不需要用户指定,程序在AJAX请求的时候会带上分页和排序需要的参数 每页显示条数:rows 当前页:page 排序字段:sort [multiS ...
- 获取wpf datagrid当前被编辑单元格的内容
原文 获取wpf datagrid当前被编辑单元格的内容 确认修改单元个的值, 使用到datagrid的两个事件 开始编辑事件 BeginningEdit="dataGrid_Beginni ...
- schemaeasyui实例:SSh结合Easyui实现Datagrid的分页显示
查了好多资料,发现还是不全,干脆自己整理吧,最少保证在我的做法正确的,以免误导读者,也是给自己做个记载吧! 克日学习Easyui,发现非常好用,界面很雅观.将学习的心得在此写下,这篇博客写SSh结合E ...
随机推荐
- MySQL自带information_schema数据库使用
MySQL的information_schema数据库是什么,有什么作用? 大家在安装或使用MYSQL时,会发现除了自己安装的数据库以外,还有一个 information_schema数据库.info ...
- 让Delphi的DataSnap发挥最大效率
让Delphi的DataSnap发挥最大效率 让Delphi的DataSnap发挥最大效率 一个DataSnap的应用程序由两个层组成: DataSnap服务器,它有一个带有一个或者更多DataSet ...
- 如何在Ubuntu下安装”.deb“、”.bin“、”.tar.gz“、”.tar.bz2“格式的软件包!
今天在Ubuntu11.10中安装Google chrome浏览器是遇到了问题,下载好的“.deb”格式的安装文件google-chrome-stable.deb双击后或者右键快捷菜单选择 Synap ...
- mysql生成varchar类型主键排序
用uuid生成20位的主键 SELECT LEFT(REPLACE(UUID(), '-', ''),20) FROM DUAL 另一种方法: 因为数据库中有字母 需要排序的时候去除字母,重新取最大值 ...
- Light OJ 1199 - Partitioning Game (博弈sg函数)
D - Partitioning Game Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- Redhat修改主机名_Red hat怎么永久修改主机名hostname(转)
有几种方式修改Redhat的主机名字,这些方法也适合其他的Centos系统,下面介绍Red hat怎么永久修改主机名hostname的三种方法. 方法一: 说明"hostname" ...
- mac 下修改Hosts文件
最近Google网站老是打不开,具体原因大家都明白,不过修改Hosts文件后,就能访问了,也算不上原创,网上一搜就能找到,自己操作记录下,希望有刚接触Mac 系统的童鞋有帮助. 第一步:打开Finde ...
- thinkphp验证码使用
在thinkphp中使用验证码很容易,只要调用thinkphp现有的方法就可以.当然,php的GD库肯定是要开的(就是在php.ini中要加载gd模块). thinkphp 3.1 --------- ...
- jquery+php实现用户输入搜索内容时自动提示
index.html <html> <head> <meta charset=;} #search_auto li a:hover{background:#D8D ...
- 自动、手动同步FishEye, JIRA的联系人信息
背景:在将FishEye和JIRA配置成共用用户信息,并且可以在二者之间自由切换,此时FishEye里的用户信息是不能更改的,只有更新了JIRA,然后让其同步至FishEye才行,如何进行设置呢? 答 ...