Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.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# 使用Jquery从动态html表列获取复选框的Id_C#_Jquery_Html_Asp.net - Fatal编程技术网

C# 使用Jquery从动态html表列获取复选框的Id

C# 使用Jquery从动态html表列获取复选框的Id,c#,jquery,html,asp.net,C#,Jquery,Html,Asp.net,在我的网页上,我使用 c#函数 public String TableForView(DataTable ViewTable) { StringBuilder html = new StringBuilder(); try { if (ViewTable.Rows.Count > 0) { html.Append("<table id='shTabl

在我的网页上,我使用 c#函数

public String TableForView(DataTable ViewTable)
    {
        StringBuilder html = new StringBuilder();
        try
        {
            if (ViewTable.Rows.Count > 0)
            {
                html.Append("<table id='shTable' class='table table-striped table-bordered'>");

                html.Append("<thead>");
                html.Append("<tr>");
                foreach (DataColumn column in ViewTable.Columns)
                {
                    html.Append("<th>");
                    html.Append(column.ColumnName);
                    html.Append("</th>");
                }
                html.Append("<th>");
                html.Append("Action & View");
                html.Append("</th>");
                html.Append("</tr>");
                html.Append("</thead>");
                html.Append("<tbody>");
                foreach (DataRow row in ViewTable.Rows)
                {
                    html.Append("<tr>");
                    foreach (DataColumn column in ViewTable.Columns)
                    {
                        html.Append("<td>");
                        html.Append(row[column.ColumnName]);
                        html.Append("</td>");
                    }
                    html.Append("<td>");
                    html.Append("<input type='checkbox' id='" + row["AccNo"] + "' name='" + row["AccNo"] + "' class='ChBoxVal' checked=''>");
                    html.Append("</td>");
                }
                html.Append("</tbody>");
                html.Append("</table>");
            }
            else
            {
                html.Append("<h4>NO DATA AVAILABLE</h4>");
            }
        }
        catch (Exception ex)
        {
            Error_ManagerClass em = new Error_ManagerClass();
            em.WriteError(ex);
        }
        return (html.ToString());
    }
但此函数不返回任何值。我对jquery有点陌生,我不知道这是否是编写jquery函数的正确方法


请帮助我找到一个解决方案,或者告诉我在哪里可以找到这个解决方案

使用
输入[type=“checkbox”]
选择复选框,然后仅按如下方式进行筛选:

$.each("#shTable tbody tr td input[type=checkbox]:checked",function(index,element){
    var $checkBox = $(element);
    var $checkBoxId  = $checkBox.attr('id');
    // you will get everything about the checkbox
});
var getChecked=function(){
返回$('#shTable').find('input[type=“checkbox”]”)
.filter(“:选中”)
.toArray()
.map(函数(x){
返回$(x).attr('id');
});
}
$(文档).on('单击','获取ID',函数(){
log(getChecked());
});

一个
两个
三
四

获取ID
使用
$(文档)。查找('input:checkbox:checked')
对于动态生成的元素我尝试过,警报(arrayOfValues)没有显示任何内容。。!!给你的答案加上一些解释以便更好地理解
$.each("#shTable tbody tr td input[type=checkbox]:checked",function(index,element){
    var $checkBox = $(element);
    var $checkBoxId  = $checkBox.attr('id');
    // you will get everything about the checkbox
});