如何将字符串数组(本例中为文件列表)绑定到中继器项目模板中的变量? [英] How do I bind a string array(list of files in my case) to a variable in the item template of a repeater?

查看:74
本文介绍了如何将字符串数组(本例中为文件列表)绑定到中继器项目模板中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将字符串数组(本例中为文件列表)绑定到项目模板中的变量?

How do I bind a string array(list of files in my case) to a variable in the item template?

这是我到目前为止的内容,但是我不确定对itemdatabound后面的代码做什么.

Here is what I have so far but I am not sure what to do for the code behind itemdatabound.

我正在尝试将每个url放入<%Photo_URL%>变量中.

I am trying to put each url in the <% Photo_URL %> variable.

任何帮助将不胜感激.

非常感谢.

页面代码

<asp:Repeater id="unorderedList" runat="server" OnItemDataBound="unorderedList_ItemDataBound">
   <HeaderTemplate>
       <ul class="thumbs noscript">
   </HeaderTemplate>
   <ItemTemplate>
          <li>
            <a class="thumb" href='<%# Photo_URL %>'>
                <img src='<%# Photo_URL %>'>
            </a>
            <div class="caption">
                <div class="download">
                    <a href='<%# Photo_URL %>'>Download Original</a>
                </div>
            </div>
        </li>
   </ItemTemplate>
   <FooterTemplate>
       </ul>
   </FooterTemplate>
</asp:Repeater>

隐藏代码

private void Page_Init(object sender, EventArgs e)
{
    string[] photos = Directory.GetFiles(ImagesLocation);
    unorderedList.DataSource = photos;
    unorderedList.DataBind();
}
protected void unorderedList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    //what goes here
}

推荐答案

            <div class="download">
                <a href='<%# Container.DataItem %>'>Download Original</a>
            </div>

这篇关于如何将字符串数组(本例中为文件列表)绑定到中继器项目模板中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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