Repeater中更新图像的的ImageUrl [英] Updating an image's ImageUrl within a Repeater

查看:180
本文介绍了Repeater中更新图像的的ImageUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能帮助我。这是一个pretty新手的问题,我害怕。我有一个中继器内的形象,我想改变其IMAGEURL基于的被传递给它的参数。

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>

有在背后的code switch语句取决于所的传递给它的是什么改变了IMAGEURL。不可避免的,但是,图像ID(imgType)是不是switch语句可见的(presumably,因为它是一个中继器内)。

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).

这是最好的方式有什么建议来实现,这将是极大的AP preciated。

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

对不起,这样的新手问题。

Sorry for such a newbie question.

推荐答案

您可以采取<一个href=\"http://stackoverflow.com/questions/701412/how-to-find-controls-in-a-repeater-header-or-footer\">look这里有关在中继页眉和页脚寻找控制的信息,但这应该总结一下:

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

这篇关于Repeater中更新图像的的ImageUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆