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

ASP
介绍一下GETROWS的用法
一个在vbscript中读取cookie的程序函数
用err.raise自定义错误信息
一段返回随机记录的代码
基于ACCESS数据库的纯asp论坛制作心得
不用Golobal.asa和session实现在线人数统计
在ASP里建表
结束ADOVB.INC的办法
存储过程分页
友情连接浏览器
怎样使用ASP实现Ping
用ASP读取Windows标准INI格式文件
使用ActiveX控件开发网页常见的问题
两个获取http页面的c#函数
将html源代码规范化,转换成XSL代码的asp工具
已调试好的asp程序在VB中转换为组件的技巧
关于如何动态地在同一页面实现两个互传
关于图片与文本同存在数据库中的具体思路
实现分页的例子-使用存储过程来实现分页
使用索引服务器- 使用索引服务器的对象

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 138 ::
收藏到网摘: 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原创,转载请注明。