Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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_Checkbox - Fatal编程技术网

C# 如何向用户显示在前端数据库中保存为“是”的复选框?

C# 如何向用户显示在前端数据库中保存为“是”的复选框?,c#,html,checkbox,C#,Html,Checkbox,这是我的网格,它是动态的。它针对每个复选框保存客户描述。也就是说,如果我将复选框标记为“个人”,那么它将在我的数据库中保存Y,否则为N。因此,现在我只想在数据库中保存Y的复选框上显示勾号。下面是我的动态网格的代码: public string getCustomerStateGrid() { string html = ""; int Count = 1; DataTable dt = getDataTableFromQuery(@"select

这是我的网格,它是动态的。它针对每个复选框保存客户描述。也就是说,如果我将复选框标记为“个人”,那么它将在我的数据库中保存Y,否则为N。因此,现在我只想在数据库中保存Y的复选框上显示勾号。下面是我的动态网格的代码:

  public string getCustomerStateGrid()
    {
        string html = ""; int Count = 1;



        DataTable dt = getDataTableFromQuery(@"select Id,cuscheckbox,CustomerDescription from CustomerState3");
        html = "<h2>    Customer State </h2><br/><table class=\"display unbreakable\" id=\"tblCustomerDetail\" style=\"width:100%; border-collapse: collapse;\"><thead>";

        #region Header

        html += "<tr><th height='40' class=\"Greyheader\" style=\"width:5%\">S.No</th>";
        html += "<th height='40' class=\"Greyheader\" style=\"width:30%\">Customer Status</th>";

        html += "<th height='40' class=\"Greyheader\" style=\"width:15%\">Customer Description</th>";

        //html += "<th class=\"Greyheader\" style=\"width:12%\">Action</th>";
        html += "</tr></thead>";

        #endregion

        #region Body
        html += "<tbody>";
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {

                html += "<tr class=\"GreyBorder\" id='tblCustomerDetail_" + dr["Id"].ToString() + "' pkid=\"" + dr["Id"].ToString() + "\"  class=\"DataRow\">";
                html += "<td class=\"GreyBorder\" style=\"text-align:center !important;\">" + Count + "</td>";


                html += "<td class=\"GreyBorder\"><input  id='txtcuscheckbox_" + dr["Id"].ToString() + "' type=\"checkbox\" style=\" text-align: right; width:95;\" value='" + dr["cuscheckbox"].ToString() + "' class=\"mediumTextField Customer Status\" /></td>";
              html += "<td class=\"GreyBorder\"><input  id='txtCustomerDescription_" + dr["Id"].ToString() + "' type=\"textbox\" style=\" text-align: right; width:95;\" value='" + dr["CustomerDescription"].ToString() + "' class=\"mediumTextField Customer Description\" /></td>";


                html += "</tr>";
                Count++;


            }
        }
        else
        {


            html += "<tr class=\"GreyBorder\" ><td style=\"text-align:center !important;\" class=\"GreyBorder\"  colspan='6'>No Data.</td></tr>";

            html += "</tr>";
        }

        html += "</tbody>";

        #endregion

        html += "<tfoot><tr class='GreyBorder'>";

        html += "<td class='GreyBorder' colspan='2'></td> ";
        html += "</tr></tfoot>";

        html += "</table><br/>";


        return html.ToString();

    }
我只想自定义这行代码

           html += "<td class=\"GreyBorder\"><input  
      id='txtcuscheckbox_" + dr["Id"].ToString() + "' 
       type=\"checkbox\" 
      style=\" text-align: right; width:95;\" value='" + d 
      dr["cuscheckbox"].ToString() + "' class=\"mediumTextField 
      Customer Status\" /></td>";
这样它就会显示勾选复选框。有人可以修改我的代码来实现这个结果吗?我们可以用三元运算符吗?
实际上,你需要:

var isChecked = 'Y';
html += isChecked == 'Y' ? "<input type=\"checkbox\" checked>" : "<input type=\"checkbox\">";
然而,您正在混合前端和后端逻辑。创建一个JSON端点将数据返回到前端并让前端生成HTML不是更好吗

编辑:

要修改当前逻辑,可以将用于创建文本框的行替换为以下内容:

var isChecked = dr["cuscheckbox"].ToString().ToUpper() == "Y" ? "checked" : string.Empty;
html += $"<td class=\"GreyBorder\"><input  id='txtcuscheckbox_{dr["Id"].ToString()}' type=\"checkbox\" style=\" text-align: right; width:95;\" class=\"mediumTextField Customer Status\" {isChecked}/></td>";

实际上,你需要:

var isChecked = 'Y';
html += isChecked == 'Y' ? "<input type=\"checkbox\" checked>" : "<input type=\"checkbox\">";
然而,您正在混合前端和后端逻辑。创建一个JSON端点将数据返回到前端并让前端生成HTML不是更好吗

编辑:

要修改当前逻辑,可以将用于创建文本框的行替换为以下内容:

var isChecked = dr["cuscheckbox"].ToString().ToUpper() == "Y" ? "checked" : string.Empty;
html += $"<td class=\"GreyBorder\"><input  id='txtcuscheckbox_{dr["Id"].ToString()}' type=\"checkbox\" style=\" text-align: right; width:95;\" class=\"mediumTextField Customer Status\" {isChecked}/></td>";

我添加了这两行代码,但它仍然显示我所有的复选框都是空的。我对这一点很陌生,所以我真的不知道我们是否可以通过json来实现这一点。但我需要修改我自己的代码来实现我的结果。这是因为我给出了一个示例,而不是对您的代码进行修改。第一步是将查询更改为实际返回值Y或N,第二步是修改创建复选框的行,以使用与我发布的类似的逻辑。您可以修改我的代码吗?由于我仍然对HTML感到困惑,生成了什么?调试代码,foreach中dr[cuscheckbox]的值是多少?我添加了这两行代码,但它仍然显示我所有的复选框都是空的。我对这一点很陌生,所以我真的不知道我们是否可以通过json来做到这一点。但我需要修改我自己的代码来实现我的结果。这是因为我给出了一个示例,而不是对您的代码进行修改。第一步是将查询更改为实际返回值Y或N,第二步是修改创建复选框的行,以使用与我发布的类似的逻辑。您可以修改我的代码吗?由于我仍然对HTML感到困惑,生成了什么?调试代码,foreach中dr[cuscheckbox]的值是多少?您使用ASP.NET吗?是的,我使用ASP.NET您使用MVC吗?您使用ASP.NET吗?是的,我使用ASP.NET您使用MVC吗?