Danny Brady
Danny Brady

Reputation: 1935

ASP.NET Server Tags

When I use:

<asp:Label id="lbCatId" runat="server" Text='<%# Eval("VideoId") %>' 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=&lt;%# Eval(&quot;VideoId&quot;) %>"


I would like to know why C# isn't generating the 'VideoId' like it is in the first example.

Upvotes: 2

Views: 3187

Answers (5)

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

Upvotes: 0

Patrick Desjardins
Patrick Desjardins

Reputation: 141013

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") %>'

Upvotes: 3

James Johnson
James Johnson

Reputation: 46077

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") %>' ...>

Upvotes: 3

Samich
Samich

Reputation: 30185

Try to change:

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

to

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

Upvotes: 1

Widor
Widor

Reputation: 13285

Have you tried:

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

Upvotes: 1

Related Questions