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

ASP
ASP+ACCESS实现的无限级目录树
ASP中字符串函数的应用
在VBScript中使用类(一)
在VBScript中使用类(二)
VS .net 2003调试javascript中两个杂症的解决
在VBScript中使用类(三)
如何在 dataGrid 上的第一列加上 CheckBox
在VBScript中使用类(四)
ASP.NET 的状态管理
用Asp写个加密和解密的类
网页制作 JSP与ASP 的比较
ASP.NET设计网络硬盘之两重要类
ASP:网上通讯簿1.00
ASP:Hack & Anti-Hack
ASP基本语法
ASP实用函数库
ASP进阶教程:给留言簿润下色
ASP进阶教程:数据库版本的留言簿
ASP进阶教程:留言簿自动发E-Mail
ASP进阶教程:留言查询功能(一)

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


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