我使用FormView在我的页面中显示数据:
<asp:FormView ID="PFull" runat="server" >
<ItemTemplate>
<div class="post_con">
<h4 class="post-headers"><asp:HyperLink ID="hprPTitle" runat="server" NavigateUrl='<%#Eval("PID","~/Paper.aspx?pid={0}")%>'><%#Eval("PTitle")%></asp:HyperLink></h4>
</div>
</ItemTemplate>
</asp:FormView>
绑定表单视图:
public void ShowFullPaper(int id)
{
DataTable dt = paper.ShowFullPaper(Convert.ToInt32(Request.QueryString["pid"]));
PFull.DataSource = dt;
PFull.DataBind();
}
现在,我想用这个超链接的文本更改页面标题:
protected void PFull_DataBound(object sender, EventArgs e)
{
this.Title = ((HyperLink)PFull.FindControl("hprPTitle")).Text;
}
但那不行。请帮帮我... 感谢。
答案 0 :(得分:2)
修改您的aspx标记如下。
<asp:FormView ID="PFull" runat="server" >
<ItemTemplate>
<div class="post_con">
<h4 class="post-headers"><asp:HyperLink ID="hprPTitle" runat="server" NavigateUrl='<%#Eval("PID","~/Paper.aspx?pid={0}")%>' Text='<%#Eval("PTitle")%>'></asp:HyperLink></h4>
</div>
</ItemTemplate>
</asp:FormView>
然后在你的ItemDataBound事件中,你可以在下面找到它。
protected void PFull_DataBound(object sender, EventArgs e)
{
this.Title = ((HyperLink)PFull.FindControl("hprPTitle")).Text;
}
答案 1 :(得分:1)
将设计更改为 -
<asp:FormView ID="PFull" runat="server" OnDataBound="PFull_DataBound" >
<ItemTemplate>
<div class="post_con">
<h4 class="post-headers"><asp:HyperLink ID="hprPTitle" runat="server" NavigateUrl='<%#Eval("Dosage","~/Paper.aspx?pid={0}")%>' Text='<%#Eval("PTitle")%>'></asp:HyperLink></h4>
</div>
</ItemTemplate>
</asp:FormView>