【发布时间】:2014-01-03 22:02:25
【问题描述】:
FormViewTitle 如果您在 ListView 或 FormView 控件 (ASP.NET) 中有标签元素,您将如何更新页面标题,该标签元素将根据您检索的数据而改变。例如一本书的标题。控件将在页面生成后检索标题。我的问题是,有没有办法在页面呈现后更新页面标题或以某种方式将此信息传递给 LabelTitle (ID) 值的 Page.Title?
请帮忙!
这是我的代码简化
<asp:FormView ID="FormViewTitle"
Runat="server"
DataSourceID="XmlDataSourceTitle"
AllowPaging="False">
<ItemTemplate>
<asp:Label ID="LabelTitle" runat="server" Text="">
<%#Eval("name") %>
</asp:Label>
</ItemTemplate>
</asp:FormView>
<asp:XmlDataSource ID="XmlDataSourceTitle"
DataFile="BooksTitles.xml"
TransformFile ="TransformRSS.xslt">
</asp:XmlDataSource>
到目前为止,我已经完成了这个(在后面的代码中)来访问 FormView 控件,但是没有工作:
if (FormViewTitle.CurrentMode == FormViewMode.ReadOnly)
{
Label pt = (Label)FormViewTitle.FindControl("LabelTitle");
this.Page.Title = pt.Text;
}
【问题讨论】: