在我的代碼隱藏中,我希望設置標籤的文本。下面是ASPX代碼:C#如何在列表視圖中設置標籤文本?
<asp:ListView ID="lstRegistrations" runat="server">
<LayoutTemplate>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<th width="80" align="left">
<asp:Label ID="lblDate" runat="server" Text="<%= GetTranslatedText(7726) %>" />
</th>
<th width="150" align="left">
<asp:Label ID="lblAuthor" runat="server" Text="<%= GetTranslatedText(7728) %>" />
</th>
<th width="290" align="left">
<asp:Label ID="lblRegistration" runat="server" Text="<%= GetTranslatedText(6671) %>" />
</th>
<th width="60" align="left">
<asp:Label ID="lblVersion" runat="server" Text="<%= GetTranslatedText(13) %>" />
</th>
</tr>
<tr>
<td colspan="4" style="height: 3px;"></td>
</tr>
<tr runat="server" id="itemPlaceholder"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="background-color:#FFFFD0;">
<td style="padding-left: 3px">
<%# ((DateTime)Eval("Date")).ToString("d-M-yyyy") %>
</td>
<td>
<%# GetStaffNameById((int)Eval("StaffID")) %>
</td>
<td>
<%# Server.HtmlEncode(Eval("Text").ToString())%>
</td>
<td>
<%# Eval("Version") %>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: #C89292">
<td style="padding-left: 3px">
<%# ((DateTime)Eval("Date")).ToString("d-M-yyyy") %>
</td>
<td>
<%# GetStaffNameById((int)Eval("StaffID")) %>
</td>
<td>
<%# Server.HtmlEncode(Eval("Text").ToString())%>
</td>
<td>
<%# Eval("Version") %>
</td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
在頂部,在layoutTemplate中我有4個標籤,我要改變的文本屬性。我試圖通過使用lstRegistrations.FindControl()方法來訪問標籤,但此方法找不到標籤。我也嘗試了Page.FindControl()方法,但是這種方法要麼找不到標籤。然後我想,我創建一個方法並在我的aspx頁面中調用它(請參閱我的代碼)。我沒有得到任何錯誤,但我沒有看到任何文字!
我在做什麼錯?
我已經使用了第一種方式。我認爲這是最好的方法。日Thnx – Martijn 2009-10-05 09:53:34