FineUI 官方论坛

标题: 解决FineUI开源版表格控件行背景色分页后异常问题 [打印本页]

作者: waitlife    时间: 2015-2-23 09:47
标题: 解决FineUI开源版表格控件行背景色分页后异常问题
非常感谢提供了这么好用的控件。

最近在测试表格控件时需要根据类型突出显示部分数据(改变行背景色),查看开源版在线示例(http://www.fineui.com/demo/#/demo/grid/grid_rowcolor.aspx)发现在分页后显示异常,再看看专业版在线示例(http://fineui.com/demo_pro/#/dem ... le_rowcssclass.aspx)就发现使用很简单:
  1. e.RowCssClass = "special";
复制代码
开源版没有“e.RowCssClass”这个属性,不过我们可以通过变通方法来解决,其实主要问题在于处理翻页后重置“highlightRows.Text”,以下是我的方法:
  1.         protected static int lastPageIndex = 0;
  2.         protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e)
  3.         {
  4.             Expense expense = e.DataItem as Expense;

  5.             if (expense == null)
  6.                 return;

  7.             #region 高亮显示收入行
  8.             if (expense.ExpenseType == null)
  9.                 return;
  10.             if (expense.ExpenseType.IsIncome)
  11.             {
  12.                 #region 判断是否已翻页,如果已翻页,重置highlightRows.Text
  13.                 if (lastPageIndex != Grid1.PageIndex)
  14.                 {
  15.                     highlightRows.Text = string.Empty;
  16.                     lastPageIndex = Grid1.PageIndex;
  17.                 }
  18.                 #endregion
  19.                 highlightRows.Text += e.RowIndex.ToString() + ",";
  20.             }
  21.             #endregion
  22.         }
复制代码
在“Grid1_RowDataBound”函数绑定也可以,一样的。测试暂时没有发现问题,请大家批评指正,希望可以帮到有用的人。


作者: sanshi    时间: 2015-2-23 15:36
这样可以实现,其实官网示例中表格分页时保持选择项采用了类似的处理
作者: sanshi    时间: 2015-2-24 20:42

刚才仔细看了一下,你的这个解决办法有问题:
  1. protected static int lastPageIndex = 0;
复制代码

把 lastPageIndex 定义为 static 会导致所有用户访问这个页面是共享这个变量,从而导致严重的错误。

正确的做法是把这个变量保存到 ViewState 中,或者一个隐藏字段中(HiddenField)。


=========我已经写了两个示例,请参考:
http://fineui.com/demo/#/demo/gr ... aging_database.aspx

http://fineui.com/demo/#/demo/gr ... owcolor_paging.aspx




作者: waitlife    时间: 2015-2-25 14:47
不错,谢谢指正!




欢迎光临 FineUI 官方论坛 (https://www.fineui.com/BBS/) Powered by Discuz! X3.4