当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用PreRender解决DataGrid分页最后一页行数不满的排版问题

ASP
asp数个使用技巧
存储过程里的递归 实现方法
非常不错的列出sql服务器上所有数据库的asp代码
防范ASP木马的十大基本原则强列建议看下
雷客图ASP站长安全助手的ASP木马查找功能
防止别人盗链的好方法推荐
图片的入库与读取的方法
用asp实现无组件生成验证码的方法2种
用asp实现检测文件编码
[asp]怎么添加验证码的解决方法
ASP文章系统解决方案实现上一页下一页
ASP编程入门进阶(三):接触脚本程序
ASP编程入门进阶(四):内置对象Request
ASP编程入门进阶(五):内置对象Response
ASP编程入门进阶(六):Cookies讲座
ASP编程入门进阶(八):内置对象Session
ASP编程入门进阶(九):内置对象Application
ASP编码优化技巧8则
ASP编程入门进阶(十):Global.asa文件
ASP编程入门进阶(十一):Chat聊天程序

ASP 中的 用PreRender解决DataGrid分页最后一页行数不满的排版问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 234 ::
收藏到网摘: n/a

 

DataGrid如果使用分页,最后一页可能不能“满页”,这样DataGrid的排版可能会出现问题,剩下的行每行太宽,整个DataGrid变得难看。

解决方法大概可以从三个地方考虑:
1、在DataSource中填上新数据行。
2、在DataGrid中填上新空白控件行。
3、在webpage中用javascript填上新的html控件行。

我采用的是第二种方法,在datagrid的prerender事件的响应方法中,在footer行之上填入空白行,代码如下:

protected virtual void SpiderSurfGrid_PreRender(object sender, System.EventArgs e)
{
  DataGridItem dgi;
  System.Web.UI.WebControls.TableCell tablecell;
  System.Web.UI.WebControls.TableRow tablerow;
  DataGrid grid = (sender as DataGrid);
  if(grid.Controls.Count == 0) return;
  System.Web.UI.WebControls.Table table = (grid.Controls[0] as System.Web.UI.WebControls.Table);
  tablerow = (System.Web.UI.WebControls.TableRow)(table.Controls[1]);

  for(int j=this.PageSize+4-table.Controls.Count;j>0;j--)
  {
    dgi = new DataGridItem(0,0,ListItemType.Item);
    for(int i=0;i<tablerow.Controls.Count;i++)
    {
      tablecell = new System.Web.UI.WebControls.TableCell();
      dgi.Cells.Add(tablecell);
    }
    table.Controls.AddAt(table.Controls.Count-2,dgi);
  }
}

说明:这里考虑的是一个有header/footer/pager行,pager在下的,绑定的datagrid。

比较奇怪的是,无法在这里给一行加上cssstyle,一旦我dgi.cssstyle="dumpTableRowClass";这些新加入的行就塌缩了,有成功的朋友请指点一下,谢谢。

athossmth原创,转载请注明。