2011-10-04 43 views
2

当我使用:ASP.NET服务器标签

<asp:Label id="lbCatId" runat="server" Text='<%# Eval("VideoId") %>' Visible="true" /> 

我得到:

<span id="ctl00_mainContent_ucCoverFlow_rptVideos_ctl00_lbCatId">5</span> 


然而,当我使用:

<asp:Image runat="server" href='Play.aspx?VideoId=<%# Eval("VideoId") %>' ID="iThumbnailFileName" CssClass="content" /> 

我得到:

<img id="ctl00_mainContent_ucCoverFlow_rptVideos_ctl01_iThumbnailFileName" class="content" href="Play.aspx?VideoId=&lt;%# Eval(&quot;VideoId&quot;) %>" 


我想知道为什么C#是不是产生了“视频ID就像是在第一个例子。

回答

3

您正在打印要执行的命令的字符串,而不是执行它。

使用:

'<%# "Play.aspx?VideoId=" + Eval("VideoId") %>' 

代替:

'Play.aspx?VideoId=<%# Eval("VideoId") %>' 
+0

这工作得很好,谢谢你的回复。 –

+0

接受格式字符串的重载对于这类事情也很有用:'<%#Eval(“VideoId”,“Play.aspx?VideoId = {0}”)%>' –

1

你试过:

<asp:Image runat="server" href='<%# "Play.aspx?VideoId=" + Eval("VideoId") %>' ID="iThumbnailFileName" CssClass="content" /> 
1

尝试改变:

href='Play.aspx?VideoId=<%# Eval("VideoId") %>' 

href='<%# "Play.aspx?VideoId=" + Eval("VideoId") %>' 
3

使用ImageUrl属性,而不是尝试。 href属性可能不知道如何解释数据绑定语法。

<asp:Image ID="Image1" runat="server" ImageUrl='Play.aspx?VideoId=<%# Eval("VideoId") %>' ...> 
0

'<%#的eval( “?Play.aspx VIDEOID = {0}”, “VIDEOID”)%>'