TrevorGoodchild TrevorGoodchild - 1 year ago 115
ASP.NET (C#) Question

.NET ListView footer controls

New to using the ListView control and I'm trying to retrieve the value of some textboxes in the layout template. Here's my aspx code:

runat="server" >
style="background-color: #FFFFFF;
border-collapse: collapse;
border-color: #999999;
<td>No data was returned.</td>

<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 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 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;

<table id="Table2" style="width: 90%" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server" width="100%">

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">
<th id="Th3" style="width: 20%; text-align:right;" runat="server">
All Gross</th>

<div style="overflow-y:scroll; height:400px;">
<table style="border: 10px; width: 100%">
<tr ID="itemPlaceholder" runat="server"></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">

<tr id="TrFooter" runat="server">
<td style="width: 50%; text-align:left;">
<td id="TdTotal" style="width: 30%; text-align:right;">
<asp:Label ID="lblTotalFunding" runat="server" /></b>
<td id="TdTotal" style="width: 20%; text-align:left;">
<asp:Label ID="lblTotalGross" runat="server" /></b>

in the lvFundingSummary_PreRender event, I'm trying to access the control as such:

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

but that's not working. I know this should be a snap, just can't quite seem to find it.

Answer Source

According to this post, use

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

in lvFundingSummary_LayoutCreated event, it should do the work