Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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# 使用列表中的数据填充2列表_C#_Html_Asp.net_List - Fatal编程技术网

C# 使用列表中的数据填充2列表

C# 使用列表中的数据填充2列表,c#,html,asp.net,list,C#,Html,Asp.net,List,我有一个关于填充2x*表的代码的问题。当代码运行时,将创建并显示表。应该是这样的。问题是表格在页面的底部。我必须滚动5秒钟才能看到它 以下是表格创建/填充: string[] myDir = Directory.GetDirectories(path); List<HyperLink> hlist = new List<HyperLink>(); foreach (string dir in myDir) {

我有一个关于填充2x*表的代码的问题。当代码运行时,将创建并显示表。应该是这样的。问题是表格在页面的底部。我必须滚动5秒钟才能看到它

以下是表格创建/填充:

string[] myDir = Directory.GetDirectories(path);

        List<HyperLink> hlist = new List<HyperLink>();

        foreach (string dir in myDir)
        {

            DirectoryInfo info = new DirectoryInfo(dir);
            string currentDirectoryName = info.Name;

            HyperLink hl = new HyperLink();
            hl.NavigateUrl = dir.ToString(); 
            hl.Text = currentDirectoryName.ToString();
            hlist.Add(hl);

            for (int i = 0; i < hlist.Count; i += 2)
            {
                TableRow row = new TableRow(); // Create the new rows
                Table1.Rows.Add(row);
                for (int j = i; j < Math.Min(i + 2, hlist.Count); j++)
                {
                    TableCell cell = new TableCell();
                    cell.CssClass = "RefItems";
                    cell.Controls.Add(hlist[j]);
                    row.Controls.Add(cell);
                }
            }

        }
你知道为什么桌子在屏幕下面这么远吗?我认为这是很明显的,因为我在过去使用过这段代码,它工作得很好。该表的HTML如下所示:

<asp:Panel ID="Panel1" runat="server">
                <asp:Table ID="Table1" runat="server"></asp:Table>
            </asp:Panel>

检查您的css,可能是页边空白或填充中的输入错误设置。用firebug检查元素。如果我去掉了ref项,它仍然是一样的。这是一个奇怪的问题:我发现了。用于填充表的for语句应该在foreach语句之外。无论如何谢谢你!