简体   繁体   中英

How to add this html using c#

I have a table in html,

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

Now I want to add this rows to it, but in page_load method, please guide,

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

You can create HTML elements in your code behind by using HtmlDocument.CreateElement, and then append it to your table with table.AppendChild. More info can be found here

Example:

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

Another option is to use a gridview or listview.

When you tag HTML and C# , I'm gonna guess it's ASP.NET :

Add <%= tableCode %> inside the table to make room for a variable:

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

Have a global variable declared in C# (global meaning outside any method):

public string tableCode;

and on page_load :

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

If it's not about ASP.NET please correct me, hope it helps ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM