ASP.NET 4访问数据应用到NavigateUrl [英] ASP.NET 4 ACCESS DATA TO APPLY TO NavigateUrl
问题描述
目前我正在学习.NET,并已到了一个砖墙,试图实现URL rounting。
I am currently learning .net and have come to a brick wall with trying to implement url rounting.
我有大部分工作正常,但我想产生在我的数据库从信息的超链接。
I have most of it working fine, but I am trying to generate hyperlinks from information in my database.
我收到的数据进行精细使用:
I am getting the data out fine using:
'portfolio navigation data
Dim rdrPortfolioNav As SqlDataReader
Dim cmdPortfolioNav As SqlCommand = New SqlCommand()
cmdPortfolioNav.CommandText = "SELECT TOP 6 [id], [date], [client], [category], [title], [body], [website], [navimage], [navdesc] FROM [portfolio] ORDER BY [date] DESC"
cmdPortfolioNav.CommandType = CommandType.Text
cmdPortfolioNav.Connection = boomSQL
cmdPortfolioNav.Connection.Open()
rdrPortfolioNav = cmdPortfolioNav.ExecuteReader(CommandBehavior.CloseConnection)
lvPortfolioNav.DataSource = rdrPortfolioNav
lvPortfolioNav.DataBind()
cmdPortfolioNav.Dispose()
在前端,我可以访问这些数据,并使用显示所有记录:
On the front end i can access the data and show all records using:
<asp:ListView ID="lvPortfolioNav" runat="server">
<ItemTemplate>
<div class="work">
<asp:HyperLink runat="server" NavigateUrl="portfolio/<%# DataBinder.Eval(Container.DataItem, "id")%>/<%# FormatLinks(DataBinder.Eval(Container.DataItem, "category")) %>/<%# FormatLinks(DataBinder.Eval(Container.DataItem, "title")) %>" ToolTip=""><span class="title"><%# DataBinder.Eval(Container.DataItem, "title")%></span></asp:HyperLink>
<asp:Image runat="server" ImageUrl="<%# DataBinder.Eval(Container.DataItem, "navimage")%>" AlternateText="<%# DataBinder.Eval(Container.DataItem, "client")%>" ToolTip="<%# DataBinder.Eval(Container.DataItem, "client")%>" />
<span class="desc"><%# DataBinder.Eval(Container.DataItem, "navdesc")%></span> </div>
</ItemTemplate>
问题是这一行:
<asp:HyperLink runat="server" NavigateUrl="portfolio/<%# DataBinder.Eval(Container.DataItem, "id")%>/<%# FormatLinks(DataBinder.Eval(Container.DataItem, "category")) %>/<%# FormatLinks(DataBinder.Eval(Container.DataItem, "title")) %>" ToolTip=""><span class="title"><%# DataBinder.Eval(Container.DataItem, "title")%></span></asp:HyperLink>
它不会从数据库中获取的值,并在HTML链接字面上出来的:
it won't get the values from the database and in the html the link literally comes out as:
<a href="../../portfolio/%3C%25#%20DataBinder.Eval(Container.DataItem,%20%22id%22)%25%3E/%3C%25%23%20FormatLinks(DataBinder.Eval(Container.DataItem,%20%22category%22))%20%25%3E/%3C%25%23%20FormatLinks(DataBinder.Eval(Container.DataItem,%20%22title%22))%20%25%3E"><span class="title">Kingston Bagpuize House Website</span></a>
同样的事情工作正常的的ImageUrl所以不知道我做错了。
the same thing works fine for the ImageUrl so not sure what i'm doing wrong.
我知道你可以在后端code生成的URL做一些事情,但我不能为我的生活找到在互联网上的任何东西.....帮助将是非常美联社preciated
I know you can do something in the backend code to generate the urls but i can't for the life of me find anything on the internet.....help would be very much appreciated.
感谢。
学家
推荐答案
您不应该使用#和写入&LT;在NavigateURL%
You should not use # in and write <% in NavigateURL.
请按照下面的例子
http://www.extremeexperts.com/Net/FAQ/PassingMulitpleParameterinURLLink.aspx
这篇关于ASP.NET 4访问数据应用到NavigateUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!