How can i use a two dimensional array with a datalist?

时间:2015-05-24 20:23:00

标签: c# asp.net

Let's say I have the following array:

    string[,] video = new string[4, 2]; // 4 videos, 2 attributes each
    video[0, 0] = "fje89t9d8hd";
    video[0, 1] = "Video 1";
    video[1, 0] = "uruioiose90";
    video[1, 1] = "Video 2";
    video[2, 0] = "5uidf90sd0f";
    video[2, 1] = "Video 3";
    video[3, 0] = "5jlk0fd9k4l";
    video[3, 1] = "Video 4";

And I want to populate a datalist like so:

    <asp:DataList ID="dlDesktop" runat="server" BackColor="White">
            <ItemTemplate>
                <h4><%# (string)Container.DataItem %> </h4>
                <br>
                <iframe width='680' height='380' src='https://www.youtube.com/embed/<%# (string)Container.DataItem %>' frameborder='0' allowfullscreen></iframe>
            </ItemTemplate>
    </asp:DataList>

So that when the page loads, all four videos are embedded and each has the corresponding title above it. What would be the proper way to do this? Do I need an ASP repeater? A foreach loop somewhere? I am lost!

0 个答案:

没有答案