2017-07-20 31 views
1

我看過的所有內容都添加了一個列頁腳而不是一個完整的行控制頁腳。我希望網格將頁腳渲染爲單個頁面有沒有辦法將Gridview頁腳添加爲單個單元格?

<tr><td> <asp:somecontrol /> </td></tr> 

row in the browser。我看着濫用傳呼機的行,但它更少定製。

+0

(或表中包含的很多列)?還是我誤解了一些東西? – Aaron

回答

3

這可以在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> 
+0

嗯,這可能比我的解決方案更好。我也通過代碼添加了按鈕,但它不會觸發RowCommand事件。 – user1431356

相關問題