如何在datalist中创建动态超链接

编程入门 行业动态 更新时间:2024-10-10 10:33:04
本文介绍了如何在datalist中创建动态超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用数据列表显示存储在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中创建动态超链接

本文发布于:2023-11-28 08:44:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:超链接   动态   如何在   datalist

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!