.NET ListView页脚控件

本文关键字:控件 ListView NET | 更新日期: 2023-09-27 18:01:00

刚开始使用ListView控件,我正在尝试检索布局模板中一些文本框的值。这是我的aspx代码:

<asp:ListView
ID="lvFundingSummary" 
OnItemCommand="lvFundingSummary_onItemCommand"
OnItemDataBound="lvFundingSummary_ItemDataBound"
runat="server" >                       
    <EmptyDataTemplate>
        <table 
            id="Table1" 
            runat="server" 
            style="background-color: #FFFFFF;
            border-collapse: collapse;
            border-color: #999999;
            border-style:none;
            border-width:1px;">
            <tr>
                <td>No data was returned.</td>
            </tr>
        </table>
    </EmptyDataTemplate> 
    <ItemTemplate>
        <tr>
            <td style="width: 50%; text-align:left; padding-top: 5px; padding-bottom:5px;">
                <asp:Label ID="lblResearchArea" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "PlName")%>' />&nbsp;
            </td>
            <td style="width: 30%; text-align:right; padding-top: 5px; padding-bottom:5px;">
                <asp:Label ID="lblFundingGross" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FundingGross", "{0:c}")%>' />&nbsp;
            </td>
            <td style="width: 20%; text-align:right; padding-top: 5px; padding-bottom:5px;">
                <asp:Label ID="lblGross" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AllGross", "{0:c}")%>' />&nbsp;
            </td>
        </tr>
    </ItemTemplate>
    <LayoutTemplate>
        <table id="Table2" style="width: 90%" runat="server">
            <tr id="Tr1" runat="server">
                <td id="Td1" runat="server" width="100%">
                    <table 
                        ID="itemPlaceholderContainer" 
                        runat="server" 
                        style="width: 98%">
                        <tr id="TrHeading"  runat="server">
                            <th id="Th1" style="width: 50%; text-align:left;" runat="server">
                                Research Area</th>
                            <th id="Th2" style="width: 30%; text-align:right;" runat="server">
                                Gross</th>
                            <th id="Th3" style="width: 20%; text-align:right;" runat="server">
                                All Gross</th>
                        </tr>                       
                    </table>
                    <div style="overflow-y:scroll; height:400px;">
                        <table style="border: 10px; width: 100%">
                            <tr ID="itemPlaceholder" runat="server"></tr>
                        </table>                            
                    </div>
                </td>
            </tr>
            <tr id="Tr2" runat="server">
                <td id="Td2" runat="server" 
                    style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
                </td>
            </tr>
            <tr id="TrFooter" runat="server">
                <td style="width: 50%; text-align:left;">
                    <b>Total(s)</b>
                </td>
                <td id="TdTotal" style="width: 30%; text-align:right;">
                    <b>
                        <asp:Label ID="lblTotalFunding" runat="server" /></b>
                </td>
                <td id="TdTotal" style="width: 20%; text-align:left;">
                    <b>
                        <asp:Label ID="lblTotalGross" runat="server" /></b>
                </td>
            </tr>
        </table>
    </LayoutTemplate>          
</asp:ListView>

在lvFundingSummary_PreRender事件中,我正试图访问控件,如下所示:

Label lbTotFund = this.lvFundingSummary.FindControl("TrFooter").FindControl("lblTotalFunding") as Label

但这不起作用。我知道这应该是一个快照,只是似乎找不到。

.NET ListView页脚控件

根据这篇文章,使用

var lbTotFund = lvFundingSummary.FindControl("lblTotalFunding") as Label;

在lvFundingSummary_LayoutCreated事件中,它应该执行