Updating an image's ImageUrl within a Repeater

限于喜欢 提交于 2019-12-06 06:23:59

问题


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.


回答1:


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");


来源:https://stackoverflow.com/questions/2920475/updating-an-images-imageurl-within-a-repeater

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!