简体   繁体   中英

Create HTML table row dynamically with c#

I want to add a row in HTML table with C# method, I have written the code but after execution the row appears at the top of the page not under HTML table.

 <tr> <th></th> <th>ID</th> <th>Date</th> <th>Plot No.</th> <th>Area</th> <th>Location</th> <th>Phase/Division</th> <th>Remarks</th> <th>Documents</th> </tr>

public void AddRow() {
    string html = "<tr>" +
        "</td> <td class=\"text-right\"><a href = \"javascript:void(0)\"  ><i class=\"fa fa-pencil\" ></i></a>  </td>" +
        "<td><p>1</p></td>" +
        "<td><input type = \"date\" runat=\"server\" style=\"width:140px\" /></td>" +
        "<td><input type =\"text\" runat=\"serve\"' style=\"width:100px\" /></td><td>" +
        "<input type = \"text\" runat=\"server\" style=\"width:100px\"/></td>" +
        "<td><input type = \"text\" Value=\"Test2\" runat=\"server\"/></td>" +
        "<td><input type = \"text\" runat=\"server\" style=\"width:100px\"/></td>" +
        "<td><input type = \"text\" runat=\"server\" style=\"height:50px\"/></td><td>" +
        "<input type = \"file\" runat=\"server\" style=\"height:50px\"/></td></tr>";
    Response.Write(html);
}    

and calling this function from <a> tag in the table.

<td>
    <a href="#" runat="server" onserverclick="Unnamed_ServerClick">
        <i class="fa fa-pencil" runat="server"></i>
    </a>
</td>

and it appears on the top like this. Result

看看 TagBuilder: https ://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/views/using-the-tagbuilder-class-to-build-html-helpers -CS

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