Repeater循环显示图片 4行3列

<table width="585" border="0" cellspacing="0" cellpadding="0">
                          <asp:Repeater ID="rpList" runat="server">
                          <ItemTemplate>
                          <tr style="width:585">
                            <td width="195" align="center">
                            <img alt="" width="185" height="136" src='Manage/CompanyInfoManage<%# Eval("Url1") %>'/>
                                </td>
                                <td width="195" align="center">
                            <img alt="" width="185" height="136" src='Manage/CompanyInfoManage<%# Eval("Url2") %>'/>
                                </td>
                                <td width="195" align="center">
                            <img alt="" width="185" height="136" src='Manage/CompanyInfoManage<%# Eval("Url3") %>'/>
                                </td>
                          </tr>
                          </ItemTemplate>
                          </asp:Repeater>

</table>

 

=============================.cs代码部分=========================================

调用:rpList.DataSource = ConvertTable(dtPicture);//显示图片
         rpList.DataBind();

 

public List<CompanyPhoto> ConvertTable(DataTable dt)
        {
            List<CompanyPhoto> list = new List<CompanyPhoto>();
            int i = 0;
            CompanyPhoto photo = new CompanyPhoto();
            foreach (DataRow row in dt.Rows)
            {
                string url = row["Url"].ToString();
                if (i == 0)
                {
                    photo = new CompanyPhoto();
                    photo.Url1 = url;
                }
                else if (i == 1)
                {
                    photo.Url2 = url;
                }
                else if (i == 2)
                {
                    photo.Url3 = url;
                    list.Add(photo);
                }
                if (i != 2)
                {
                    i++;
                }
                else
                {
                    i = 0;
                }
            }
            if (i != 0)
            {
                list.Add(photo);
            }
            return list;
        }

 

        public class CompanyPhoto
        {
            public string Url1 { get; set; }
            public string Url2 { get; set; }
            public string Url3 { get; set; }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值