ASP.NET Server Tags
When I use:
<asp:Label id="lbCatId" runat="server" Text='<%# Eval("Vid开发者_StackOverflow社区eoId") %>' Visible="true" />
I get:
<span id="ctl00_mainContent_ucCoverFlow_rptVideos_ctl00_lbCatId">5</span>
However when I use:
<asp:Image runat="server" href='Play.aspx?VideoId=<%# Eval("VideoId") %>' ID="iThumbnailFileName" CssClass="content" />
I get:
<img id="ctl00_mainContent_ucCoverFlow_rptVideos_ctl01_iThumbnailFileName" class="content" href="Play.aspx?VideoId=<%# Eval("VideoId") %>"
I would like to know why C# isn't generating the 'VideoId' like it is in the first example.
You are printing the string of the command you want to execute instead of executing it.
Use :
'<%# "Play.aspx?VideoId=" + Eval("VideoId") %>'
Instead of :
'Play.aspx?VideoId=<%# Eval("VideoId") %>'
Try using the ImageUrl
property instead. The href
attribute probably doesn't know how to interpret databinding syntax.
<asp:Image ID="Image1" runat="server" ImageUrl='Play.aspx?VideoId=<%# Eval("VideoId") %>' ...>
Have you tried:
<asp:Image runat="server" href='<%# "Play.aspx?VideoId=" + Eval("VideoId") %>' ID="iThumbnailFileName" CssClass="content" />
Try to change:
href='Play.aspx?VideoId=<%# Eval("VideoId") %>'
to
href='<%# "Play.aspx?VideoId=" + Eval("VideoId") %>'
'<%# Eval("VideoId","Play.aspx?VideoId={0}") %>'
精彩评论