Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将二维数组与数据列表一起使用?_C#_Asp.net - Fatal编程技术网

C# 如何将二维数组与数据列表一起使用?

C# 如何将二维数组与数据列表一起使用?,c#,asp.net,C#,Asp.net,假设我有以下数组: 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,

假设我有以下数组:

    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";
我想像这样填充一个数据列表:

    <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>

因此,当页面加载时,所有四个视频都被嵌入,并且每个视频上面都有相应的标题。正确的方法是什么?我需要ASP中继器吗?某个地方的foreach循环?我迷路了

我强烈建议远离web表单和数组。在这一点上,两者都被MVC和泛型集合所取代。数组仍然有一些用途,因为它们相对于列表来说是内存高效的。回答您问题的神奇词汇是绑定和数据源。但是一旦绑定,如何确定要将数组的哪个部分绑定到正确的位置?不要使用数组。为每个视频创建一个具有所需各种属性的类。这看起来像什么?