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

ASP
Microsoft 脚本编码器(3) --- 使用脚本编码器
WAP中的ASP技术(一)
WAP中的ASP技术(二)
WAP中的ASP技术(三)
WAP中的ASP技术(四)
在ADO使用SELECT语法一
在ADO使用SELECT语法二
在ADO使用SELECT语法三
在ADO使用SELECT语法四
在ADO使用SELECT语法五
在ADO使用SELECT语法六
Asp+语法介绍(六)----数据库篇
vbscript错误代码及对应解释大全
ASP系列讲座(三)创建 ASP 页
ASP系列讲座(四)使用脚本语言
ASP系列讲座(五)使用变量和常量
ASP系列讲座(六)编写过程
ASP系列讲座(七)使用组件和对象
ASP系列讲座(八)使用集合
ASP系列讲座(九)设置对象作用域

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


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