我看過的所有內容都添加了一個列頁腳而不是一個完整的行控制頁腳。我希望網格將頁腳渲染爲單個頁面有沒有辦法將Gridview頁腳添加爲單個單元格?
<tr><td> <asp:somecontrol /> </td></tr>
row in the browser。我看着濫用傳呼機的行,但它更少定製。
我看過的所有內容都添加了一個列頁腳而不是一個完整的行控制頁腳。我希望網格將頁腳渲染爲單個頁面有沒有辦法將Gridview頁腳添加爲單個單元格?
<tr><td> <asp:somecontrol /> </td></tr>
row in the browser。我看着濫用傳呼機的行,但它更少定製。
這可以在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可以用來容納控件。
<asp:TemplateField>
<ItemTemplate>
<%# Eval("myColumn") %>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="Label1" runat="server" Text="Footer"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
嗯,這可能比我的解決方案更好。我也通過代碼添加了按鈕,但它不會觸發RowCommand事件。 – user1431356