简体   繁体   English

ASP.NET - 从数据库中检索图像URL并在转发器中显示它们

[英]ASP.NET - Retrieve image URLs from database and show them in repeater

Basically I have a database with two tables, that is, Updates table and Images table. 基本上我有一个包含两个表的数据库,即Updates表和Images表。

The images table is associated with the Updates table through a foreign key "Update_ID". images表通过外键“Update_ID”与Updates表相关联。

Now, in my page, I have a repeater which shows all the entries in the Updates table. 现在,在我的页面中,我有一个转发器,显示Updates表中的所有条目。 What I want to do is to display all the images associated with each and every Update_ID in the repeater control. 我想要做的是显示与转发器控件中的每个Update_ID相关联的所有图像。

The problem is that each Update_ID can have as many images as one wants associated with it. 问题是每个Update_ID可以拥有与想要关联的图像一样多的图像。 If there was only one image per update_ID then there would be no problem as I would allocate one Image control and that's it. 如果每个update_ID只有一个图像,那么就没有问题,因为我会分配一个Image控件,就是这样。 However, I don't know how many Image controls I am going to have. 但是,我不知道我将拥有多少个图像控件。

How can I show the images associated with each update_ID in its respective repeater? 如何在各自的转发器中显示与每个update_ID关联的图像? Thanks :) 谢谢 :)

Use a Repeater inside each ItemTemplate of the main repeater and Bind the new repeater to the images collection of each update record 在主转发器的每个ItemTemplate中使用Repeater ,并将新转发器绑定到每个更新记录的images集合中

<asp:Repeater runat="server" ID="rptrUpdates">
   <ItemTemplate>
           <asp:Repeater runat="server" ID="rptrImages">
             <ItemTemplate>
               <img src="<%#Eval("imgUrl")"/>
             </ItemTempate>
           </asp:Repeater>
   </ItemTempate>
</asp:Repaeter>

and in code behind inside in ItemDataBound event of main repeater bind the child one 并且在主要转发器的ItemDataBound事件内部的代码中绑定了一个子代码

protected void rptrUpdates_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if(e.Item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
   {
      Repeater rptrImages = (Repeater)e.Item.FindControl("rptrImages");
      rptrImages.DataSource = ((Updates)e.Item.DataItem).Images;
      rptrImages.DataBind();
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在asp.net中从数据库中检索图像 - Retrieve image from database in asp.net ASP.NET C#从SQL Server数据库获取检索并显示图像 - ASP.NET C# Get retrieve and show image from SQL Server database 从SQL Server检索图像以在ASP.NET应用程序中显示 - Retrieve an image from SQL Server to show it in an ASP.NET app 如何在asp.net中的中继器控件列中显示图像? - how to show image in the column of repeater control in asp.net? 通过asp.net使用linQ从数据库检索图像 - retrieve an image from database using linQ by asp.net 从数据库(mysql)检索ASP.NET图像(BLOB) - ASP.NET image(BLOB) retrieve from database(mysql) 从 SQL 服务器绑定图像到 ASP.NET 中的中继器未加载? - Binding image from SQL Server to repeater in ASP.NET not loading? ASP.NET Datagrid从数据库C#中检索选择的项目,并使它们像表一样排序 - ASP.NET Datagrid retrieve choosed items from database C# and make them sorted like table ASP.NET:在转发器中填充一个下拉列表(来自数据库),并从转发器数据仓库中为其分配默认值 - ASP.NET: Populate a dropdown list within a repeater (from database), and assign it a default value from the repeater datascource 如何从SQL Server数据库中检索图像字段civilimage1,civilimage2,以在带有vb.net或c#的ASP.NET中使用图像控件进行显示? - How to retrieve image fields civilimage1,civilimage2 from SQL Server database to show using image control in ASP.NET with vb.net or c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM