DataGrid默认的分页样式看上去不容易看清当前是第几页,可以使用下面的方法改进。
在DataGrid触发ItemCreated事件时执行以下代码:
if
(e.Item.ItemType
==
ListItemType.Pager)
{
TableCell pager = (TableCell) e.Item.Controls[0];
for (int i = 0; i < pager.Controls.Count; i += 2)
{
Object o = pager.Controls[i];
if (o is LinkButton)
{
// 非当前页码
LinkButton linkButton = (LinkButton) o;
// 这里可以设置更多样式
linkButton.Text = "[ " + linkButton.Text + " ]";
}
else
{
// 当前页码
Label label = (Label) o;
// 这里也可以设置更多样式
label.Text = "第 " + label.Text + " 页";
}
}
}
{
TableCell pager = (TableCell) e.Item.Controls[0];
for (int i = 0; i < pager.Controls.Count; i += 2)
{
Object o = pager.Controls[i];
if (o is LinkButton)
{
// 非当前页码
LinkButton linkButton = (LinkButton) o;
// 这里可以设置更多样式
linkButton.Text = "[ " + linkButton.Text + " ]";
}
else
{
// 当前页码
Label label = (Label) o;
// 这里也可以设置更多样式
label.Text = "第 " + label.Text + " 页";
}
}
}
当然DataGrid的属性要做相应设置,要允许翻页,而且以数字做翻页。