ASP.NET Webforms Gridview页脚

时间:2014-10-13 04:08:30

标签: c# css gridview webforms

在ASP.NET webforms中,有没有办法配置FooterTemplate的{​​{1}}以允许页脚溢出,但是还要保留上面的列宽,如下所示?就像现在一样,任何页脚溢出也会拉伸它上面的细胞。

Layout

1 个答案:

答案 0 :(得分:1)

您可以使用gridview_rowcreated()事件来完成此操作。

只是在事件中允许rowspan和列包含所需的列和行

根据您的要求修改它。

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Footer)
    {
        GridView FooterGrid = (GridView)sender;
        GridViewRow FooterRow = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert);
        TableCell Cell_Footer = new TableCell();
        Cell_Footer.Text =""; // As per your requirement
        Cell_Footer.HorizontalAlign = HorizontalAlign.Center;
        Cell_Footer.ColumnSpan = 2;
        HeaderRow.Cells.Add(Cell_Footer);

        Cell_Footer = new TableCell();
        Cell_Footer.Text = ""; // As per your requirement
        Cell_Footer.HorizontalAlign = HorizontalAlign.Center;
        Cell_Footer.ColumnSpan = 1;
        Cell_Footer.RowSpan = 2;
        FooterRow.Cells.Add(Cell_Footer);

        Cell_Footer = new TableCell();
        Cell_Footer.Text = ""; // as per your requiremnt
        Cell_Footer.HorizontalAlign = HorizontalAlign.Center;
        Cell_Footer.ColumnSpan = 3;
        FooterRow.Cells.Add(Cell_Footer);

        GridView1.Controls[0].Controls.AddAt(0, FooterRow);

    }
}

如果想要更多解释请通过链接 http://codedisplay.com/merge-merging-or-split-spliting-gridview-header-row-or-columns-in-asp-net-c-vb-net/