问题描述
我正在使用数据列表显示存储在SQL Server数据库中的新闻报道摘要。
< asp: DataList ID =DL_NewsSummaryrunat =serverDataKeyField =newsItemId
DataSourceID =DS_NewsSummary>
< ItemTemplate>
< h3>
< asp:HyperLink ID =headlineLinkrunat =serverText ='<%#Eval(headline)%>'NavigateUrl =#/>
< / h3>
< asp:Label ID =dateLabelrunat =serverText ='<%#Eval(date)%>'/>
< br />
< asp:Label ID =introLabelrunat =serverText ='<%#Eval(intro)%>'/>
< hr />
< / ItemTemplate>
< / asp:DataList>
当用户点击标题超链接时,他们应该在单独的页面上看到完整的故事, news.aspx
。此页面将从查询字符串中获取 newsItemId
,并使用与该ID相关联的故事填充页面,例如 news.aspx?newsItemId = 1
。
然而,当我将navigateUrl字段更改为以下内容时,我得到一台服务器标签形成错误。
< asp:HyperLink ID =headlineLinkrunat =serverText ='< %#Eval(标题)%>'NavigateUrl =news.aspx?newsItemId =<%#Eval(newsItemId)%> />
非常感谢任何帮助
NavigateUrl ='<%#news.aspx?newsItemId = + Eval(newsItemId)%>'
I am using a datalist to display a summary of news stories stored in a SQL Server database.
<asp:DataList ID="DL_NewsSummary" runat="server" DataKeyField="newsItemId"
DataSourceID="DS_NewsSummary">
<ItemTemplate>
<h3>
<asp:HyperLink ID="headlineLink" runat="server" Text = '<%# Eval("headline") %>' NavigateUrl="#" />
</h3>
<asp:Label ID="dateLabel" runat="server" Text='<%# Eval("date") %>' />
<br />
<asp:Label ID="introLabel" runat="server" Text='<%# Eval("intro") %>' />
<hr />
</ItemTemplate>
</asp:DataList>
When the user clicks the headline hyperlink they should be taken to the full story on a separate page, news.aspx
. This page will get the newsItemId
from the querystring and populate the page with the story associated with that id e.g. news.aspx?newsItemId=1
.
However when I change the navigateUrl field to the following I get a server tag not well formed error.
<asp:HyperLink ID="headlineLink" runat="server" Text = '<%# Eval("headline") %>' NavigateUrl="news.aspx?newsItemId=<%# Eval("newsItemId") %>" />
Any help is greatly appreciated
Try this:
NavigateUrl='<%# "news.aspx?newsItemId=" + Eval("newsItemId") %>'
这篇关于如何在datalist中创建动态超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!