views:

195

answers:

1

I know how you can set an tag's url attribute programmatically in c#, but it seems when I try to access the image element inside of a tag I cannot access it.

The is residing in the <AlternatingItemTemplate>.

NOTE: I am only having this issue inside the <AlternatingItemTemplate>

Now the ListView tag is also databound.(this is probably why I cannot access, because it isn't guaranteed that it will even exist perhaps).

How can I get around this so that I can display my images programmatically or is there a better solution?

Here's the source:

    <asp:ListView ID="ListView_Comments" runat="server"
DataKeyNames="ReviewID,ProductID,Rating" DataSourceID="EDS_CommentsList">
<ItemTemplate>
<tr style="background-color:#EDECB3;color: #000000;"> <td><%# Eval("CustomerName") %></td>
<td> <img src='Styles/Images/ReviewRating_d<%# Eval("Rating") %>.gif' alt="">
<br />
</td>
<td> <%# Eval("Comments") %>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color:#F8F8F8;"> <td><%# Eval("CustomerName") %></td>
<td> 
<img id="rateImage" src="" alt="" runat="server" />
......
A: 

Should be able to access it in the codebehind in the OnItemDatabound Event. There u can check to see if its an alternating item or not then use FindControl and u should have access to it.

Or, if your image is stored in your datasource y not just set the src using <%# Eval %>

ANC_Michael
Yes, I considered using <%#Eval %> but when I place it in the src attribute it has no affect.I applied it like this: <img id="rateImage" src='Styles/Images/ReviewRating_da<%# Eval("Rating") %>.gif' runat="server"/>
loyalpenguin
It Works! Thanks.
loyalpenguin