简体   繁体   English

如何从 C#、ASP.net 添加 HTML 输入

[英]How can i add HTML input from C#, ASP.net

I have this HTML table in my aspx page which will be populated from datatable, and I need to put a checkbox at the start of each row.我的 aspx 页面中有这个 HTML 表,它将从数据表中填充,我需要在每一行的开头放置一个复选框。 I tried to use the code below in which I used StringBuilder and I also tried using TagBuilder but nothing works.我尝试使用下面使用StringBuilder的代码,我也尝试使用TagBuilder但没有任何效果。

//Building an HTML string.
StringBuilder html = new StringBuilder();

//Building the Data rows.
foreach (DataRow row in dt.Rows)
{
    html.Append("<tr>");

    html.Append("<td>");
    html.AppendFormat("< input type = 'checkbox' />"); //here it displays the tag as string
    html.Append("</td>");

    foreach (DataColumn column in dt.Columns)
    {
        html.Append("<td>");
        html.Append(row[column.ColumnName]); //here it displays the data
        html.Append("</td>");
    }
    html.Append("</tr>");

}
datatableBody.Controls.Add(new Literal
{
    Text = html.ToString()
});

Here is the Table :这是表:

<table class="table dataTable my-0" id="dataTable" style="text-align:center">
    <thead>
        <tr>
            <th><input type="checkbox" /></th>
            <th>Matricule</th>
            <th>Prenom</th>
            <th>Date</th>
            <th>Periode</th>
            <th>Total</th>
        </tr>
    </thead>
    <tbody id="datatableBody" runat="server">
    </tbody>
</table>

Here are the results:结果如下:

显示结果的图像

I also want to be able to access the value of the checkbox (checked or not).我还希望能够访问复选框的值(选中或不选中)。

I am not sure about that but I think you can use something like this :我不确定,但我认为你可以使用这样的东西:

html.Append("<input type=\"checkbox\" name=\"CheckSelect").Append(row["id"]).Append("\">");

Or If you don't mind to use Jquery, here is a solution for you :或者,如果您不介意使用 Jquery,这里有一个适合您的解决方案:

https://forums.asp.net/t/2156602.aspx?Appending+the+Checkbox+to+the+HTML+Table+ https://forums.asp.net/t/2156602.aspx?Appending+the+Checkbox+to+the+HTML+Table+

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将项目添加到列表中<T>从控制器中的表单输入而不使用视图? ASP.NET MVC C# - How can I add items to a list<T> from form input in a controller without using views? ASP.NET MVC C# 如何根据asp.net C#下拉菜单中的用户输入在图表上添加一条直线 - How can I add a straight line on my chart on the basis of user input from drop down menu in asp.net c# 如何从C#ASP.Net应用程序中获取tinymce HTML内容? - How can I get the tinymce HTML content from within a C# ASP.Net application? 如何将项目从结构 asp.net c# 添加到下拉列表 - How can I add items to a dropdownlist from a struct asp.net c# 如何将HTML图像滑块添加到asp.net C#网站 - How do I add HTML image slider into a asp.net c# Website 如何在asp.net c#的“添加到购物车”页面中添加多个产品? - How can I add multiple products in “add to cart” page of asp.net c#? Html,C#,ASP.NET如何重复包含标签的div标签中的内容来显示数据库中的所有记录? - Html, C#, ASP.NET How can i repeat the contents in div tag containing labels to display all records from database? 如何获取输入 onchange 事件以调用 c# 方法并将值传递给它 asp.net - How can i get input onchange event to call a c# method and pass a value into it asp.net 如何在Asp.net C#中验证Web服务中的输入字段? - How I can validate input field in Webservice in Asp.net C#? 我如何在ex.html c#中使用extern html文件作为附件并将其发送到电子邮件地址? - How I can use a extern html file for a attachment in asp.net c# and send it to a email address?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM