Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.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添加此html#_C#_Html - Fatal编程技术网

C# 如何使用c添加此html#

C# 如何使用c添加此html#,c#,html,C#,Html,我有一张html表格 <div id="top-body" class="p-body" style="height:800px; overflow:auto; display:block !important;"> <table id="o-Table" class="myTable"></table> </div> 现在我想把这些行添加到它上面,但是在页面加载方法中,请引导 $("#o-Table").append(

我有一张html表格

<div id="top-body" class="p-body" style="height:800px; overflow:auto; display:block !important;">
    <table id="o-Table" class="myTable"></table>
</div>

现在我想把这些行添加到它上面,但是在页面加载方法中,请引导

  $("#o-Table").append(
            "<tr class='myRow'>" +
            "   <div class='myRow'>" +
            "       <td class='myCell'  onclick='DoSomething(\"" + someString + "\")'>" +
            "           <div class='myCell2'>" + someString2 + "</div>" +
            "       </td>" +
            "   </div>" +
            "</tr>");
$(“#o-Table”)。追加(
"" +
"   " +
"       " +
“”+someString2+“”+
"       " +
"   " +
"");

当你标记
HTML
C
时,我猜它是
ASP.NET

在表中添加
,为变量腾出空间:

<div id="top-body" class="p-body" style="height:800px; overflow:auto; display:block !important;">
    <table id="o-Table" class="myTable">  <%= tableCode %>  </table>
</div>
并在加载页面上执行以下操作:

tableCode = "<tr class='myRow'>" +
            "   <div class='myRow'>" +
            "       <td class='myCell'  onclick='DoSomething(\"" + someString + "\")'>" +
            "           <div class='myCell2'>" + someString2 + "</div>" +
            "       </td>" +
            "   </div>" +
            "</tr>";
tableCode=“”+
"   " +
"       " +
“”+someString2+“”+
"       " +
"   " +
"";

如果不是关于ASP.NET的
ASP.NET
请纠正我,希望有帮助;)

您可以使用HtmlDocument.CreateElement在代码中创建HTML元素,然后使用table.AppendChild将其附加到表中。 可以找到更多信息

例如:

HtmlElement row = doc.CreateElement("TR");
table.AppendChild(row);

另一种选择是使用gridview或listview。

我只需要弄清楚,如何在C#中动态地向表中添加行,表将已经存在。我不是这里的专家,但您需要知道如何在jQuery或C#中使用它(如标题所述)?它是asp.net,但正如我前面所述,我必须动态地添加许多行。你是说使用JavaScript吗?什么是文档,如何获取表表应该是表元素(o-table)的ID。现在无法测试,但您可能可以使用System.Web.UI.WebControls.TableRow row=new System.Web.UI.WebControls.TableRow()创建行;
HtmlElement row = doc.CreateElement("TR");
table.AppendChild(row);