有没有办法将Gridview页脚添加为单个单元格?

时间:2017-07-20 17:37:51

标签: asp.net gridview

我看过的所有内容都添加了一个列页脚,而不是一个完整的行控制页脚。我希望Grid将页脚呈现为单个

<tr><td> <asp:somecontrol /> </td></tr> 
浏览器中的

行。我看着滥用寻呼机行,但它的可定制性更低。

1 个答案:

答案 0 :(得分:4)

这可以在RowDataBound事件中轻松完成。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    //check if the row is a footer row
    if (e.Row.RowType == DataControlRowType.Footer)
    {
        //span the first cell with the number of columns
        e.Row.Cells[0].ColumnSpan = e.Row.Cells.Count;

        //hide all other columns
        for (int i = 1; i < e.Row.Cells.Count; i++)
        {
            e.Row.Cells[i].Visible = false;
        }
    }
}

然后可以使用第一个TemplateField来保存Control。

<asp:TemplateField>
    <ItemTemplate>
        <%# Eval("myColumn") %>
    </ItemTemplate>
    <FooterTemplate>
        <asp:Label ID="Label1" runat="server" Text="Footer"></asp:Label>
    </FooterTemplate>
</asp:TemplateField>