1

文字列配列 (私の場合はファイルのリスト) を項目テンプレートの変数にバインドするにはどうすればよいですか?

ここに私がこれまでに持っているものがありますが、itemdatabound の背後にあるコードに対して何をすべきかわかりません。

<% Photo_URL %> 変数に各 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
}
4

4 に答える 4

3
            <div class="download">
                <a href='<%# Container.DataItem %>'>Download Original</a>
            </div>
于 2013-07-31T19:19:28.980 に答える
2

ItemDataBoundイベントは必要ありません<%# Container.DataItem %>。次のような構文を使用するだけです。

<ItemTemplate>
      <li>
        <a class="thumb" href='<%# Photo_URL %>'>
            <img src='<%# Container.DataItem %>'>
        </a>
        <div class="caption">
            <div class="download">
                <a href='<%# Container.DataItem %>'>Download Original</a>
            </div>
        </div>
    </li>

于 2013-07-31T19:19:16.693 に答える
2

Container.DataItem次の構文を使用できます。

<asp:Repeater id="unorderedList" runat="server" OnItemDataBound="unorderedList_ItemDataBound">
   <HeaderTemplate>
       <ul class="thumbs noscript">
   </HeaderTemplate>
   <ItemTemplate>
          <li>
            <a class="thumb" href='<%#Container.DataItem%>'>
                <img src='<%#Container.DataItem%>'>
            </a>
            <div class="caption">
                <div class="download">
                    <a href='<%#Container.DataItem%>'>Download Original</a>
                </div>
            </div>
        </li>
   </ItemTemplate>
   <FooterTemplate>
       </ul>
   </FooterTemplate>
</asp:Repeater>
于 2013-07-31T19:19:30.513 に答える