我的列表视图ItemTemplate如下
<a href='<%# getpath(Eval("IMAGE_PATH")) %>' title='<%# Eval("IMAGE_DESCRIPTION") %>'>
<asp:Image ID="capty" CssClass="capty" runat="server"
AlternateText='<%# Eval("IMAGE_DESCRIPTION") %>'
ImageUrl='<%# retriveurl(Eval("IMAGE_PATH")) %>'
Height="100px" Width="150px">
</asp:Image>
</a>
我的代码隐藏源是
int count=ListView1.Items.Count;
List<ImageGallery> _list = new List<ImageGallery>();
for (int i = 0; i < count; i++)
{
ImageGallery ob = new ImageGallery();
ob.ImageName = ??
ob.Description = ??
_list.Add(ob);
}
现在我想将Eval(“IMAGE_DESCRIPTION”)数据插入到ob.Description和ob.ImageName = Eval(“IMAGE_ID”)。如何做?
List<ImageGallery> _list = new List<ImageGallery>();
for (int i = 0; i < ListView1.Items.Count; i++)
{
ImageGallery ob = new ImageGallery();
ob.ImageName = "";
ob.Description = " ";
_list.Add(ob);
}
答案 0 :(得分:0)
您可以使用FindControl
来获取图片。你传递了你想要找到的控件的ID(“capty”);它返回一个对象,因此您需要将其转换/取消装入控件类型Image
。见下文:
List<ImageGallery> _list = new List<ImageGallery>();
for (int i = 0; i < ListView1.Items.Count; i++)
{
Image image = (Image)ListView1.Items[i].FindControl("capty");
ImageGallery ob = new ImageGallery();
ob.ImageName = "";
ob.Description = image.AlternateText;
_list.Add(ob);
}