如何将字符串数组(在我的例子中是文件列表)绑定(bind)到项目模板中的变量?
这是我目前所拥有的,但我不确定如何处理 itemdatabound 背后的代码。
我试图将每个 url 放入 <% Photo_URL %> 变量中。
如有任何帮助,我们将不胜感激。
提前致谢。
页面代码
<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>
关于c# - 如何将字符串数组(在我的例子中是文件列表)绑定(bind)到中继器项目模板中的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17978945/