0

我的列表视图 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); 
}
4

1 回答 1

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); 
}
于 2012-09-27T05:29:32.907 回答