dimanche 26 janvier 2020

How to show checkboxes to user that are saved as yes in database at frontend?

This is my grid which is dynamic. It is saving customer description against each checkbox. That is, if I mark the checkbox against Individual then it saves Y in my database otherwise N. so Now I just want to show tick on checkboxes that are saved Y in the database. Below is the code for my dynamic grid:

  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();

    }

I just want to customize this line of code

           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>";

so that it shows tick on checkbox. Can anyone modify my code to achieve this result? Is there any way we can do using ternary operator? enter image description here




Aucun commentaire:

Enregistrer un commentaire