日期:2014-05-17  浏览次数:20478 次

重写gridview控件 当数据源为空时 怎么显示footer行
重写了gridview控件 当数据源为空的时候 重写了表头
 protected override void Render(HtmlTextWriter writer)
        {
            if (this.Rows.Count == 0 || this.Rows[0].RowType == DataControlRowType.EmptyDataRow)
            {
                RenderEmptyContent(writer);
            }
            else
            {
                base.Render(writer);
            }
        }
        protected virtual void RenderEmptyContent(HtmlTextWriter writer)
        {
            Table t = new Table();
            t.CssClass = this.CssClass;
            t.GridLines = this.GridLines;
            t.BorderStyle = this.BorderStyle;
            t.BorderWidth = this.BorderWidth;
            t.CellPadding = this.CellPadding;
            t.CellSpacing = this.CellSpacing;
            t.HorizontalAlign = this.HorizontalAlign;
            t.Width = this.Width;
            t.CopyBaseAttributes(this);
            TableRow row = new TableRow();
            t.Rows.Add(row);

            foreach (DataControlField f in this.Columns)
            {
                TableHeaderCell cell = new TableHeaderCell();
                cell.Text = f.HeaderText;
                row.Cells.Add(cell);
            }
            t.RenderControl(writer);

        }
可是这样footer行显示不出来   有么有什么好的方法  不想采用插入空行再删除的方式 太麻烦 
谁能指导一下 谢谢
------最佳解决方案--------------------
那在循环里可以改成这样:

foreach (DataControlField f in this.Columns)
{
TableHeaderCell cell = new&