Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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/apache-spark/6.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,我试图通过后端动态创建一个表。我已经检查了我的代码,没有发现任何问题。这张桌子根本没有显示出来。这是代码- Table tblEmployeeList = new Table(); foreach (DataRow row in dtEmployList.Rows) { TableRow tRow = new TableRow(); foreach(DataColumn dCol in dtEmployList.Columns) { TableCell

我试图通过后端动态创建一个表。我已经检查了我的代码,没有发现任何问题。这张桌子根本没有显示出来。这是代码-

Table tblEmployeeList = new Table();

foreach (DataRow row in dtEmployList.Rows)
{
    TableRow tRow = new TableRow();

    foreach(DataColumn dCol in dtEmployList.Columns)
    {
        TableCell tCell = new TableCell();
        tCell.Text = row["Username"].ToString();
        tRow.Cells.Add(tCell);
    }
    tblEmployeeList.Rows.Add(tRow);
}

您已经在服务器端创建了一个html表,但没有添加到页面的html中。在HTML中添加一个div,使其在runat=“server”中运行。完成添加行后,在DIV中添加当前表

在HTML中

<div id="div1" runat="server"></div>
你的代码是

Table tblEmployeeList = new Table();
foreach (DataRow row in dtEmployList.Rows)
{
        TableRow tRow = new TableRow();

        foreach(DataColumn dCol in dtEmployList.Columns)
        {
            TableCell tCell = new TableCell();
            tCell.Text = row["Username"].ToString();
            tRow.Cells.Add(tCell);
        }

        tblEmployeeList.Rows.Add(tRow);
 }
div1.Controls.Add(tblEmployeeList); //This will show the table in the page

那么生成的HTML是什么样子的呢?我应该考虑检查一下!谢谢它不包含任何位置的表。是否需要先在前端创建表,然后使用它创建新行和单元格/Yes。您应该首先使用runat=“server”在前端创建一个表。我试过了,没有改变。谢谢你的知识和帮助!是否可以让表格继续在右侧,而不必向下滚动到表格底部?您可能正在查找表格周围的滚动条,
Table tblEmployeeList = new Table();
foreach (DataRow row in dtEmployList.Rows)
{
        TableRow tRow = new TableRow();

        foreach(DataColumn dCol in dtEmployList.Columns)
        {
            TableCell tCell = new TableCell();
            tCell.Text = row["Username"].ToString();
            tRow.Cells.Add(tCell);
        }

        tblEmployeeList.Rows.Add(tRow);
 }
div1.Controls.Add(tblEmployeeList); //This will show the table in the page