开发者

Updating an image's ImageUrl within a Repeater

I hope someone can help me. It's a pretty newbie question, I'm afraid. I have an image inside a repeater, and I would like to change its IMAGEURL based on parameter that's being passed to it.

<asp:Repeater ID="Repeater" runat="server">
     <HeaderTemplate>
         <asp:Image ID="imgType" runat="server" />   
     </HeaderTemplate>         
开发者_开发问答     <ItemTemplate>     
         <%# Eval("DisplayName")%>            
     </ItemTemplate>
     <SeparatorTemplate>
         <hr />
     </SeparatorTemplate>
 </asp:Repeater>

There is a SWITCH statement in the code behind that is altering the IMAGEURL depending on what's being passed to it. Inevitably, however, the images ID ("imgType") is not visible to the SWITCH statement (presumably because it's inside a REPEATER).

Any suggestions on the best way to implement this would be greatly appreciated.

Sorry for such a newbie question.


You can take a look here for information on finding controls in a repeaters header and footer, but this should sum it up:

// Get control from <HeaderTemplate>
Image imgTypeControl = (Image)myRepeater.Controls[0].Controls[0].FindControl("imgType");

// Get control from <FooterTemplate>
Image imgTypeControl = (Image)myRepeater.Controls[myRepeater-Controls.Count - 1].Controls[0].FindControl("imgType");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜