title: HTML generate rowspan in html table string
body: <p>I have the following code, which adds rowspan to a datatable in an html string, but I want it not to receive as a parameter a datatable, but instead to receive as a parameter an html string in C#.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      DataTable dt = new DataTable();
      dt.Columns.Add("Subject");
      dt.Columns.Add("Code");
      dt.Columns.Add("Test");
      dt.Columns.Add("Class");
      dt.Rows.Add("Math", "9", "ABC", "D1");
      dt.Rows.Add("Math", "9", "ABD", "D2");
      dt.Rows.Add("Math", "9", "ABE", "D3");
      dt.Rows.Add("Math", "9", "ABF", "D4");
      dt.Rows.Add("Science", "91", "ABG", "D1");
      dt.Rows.Add("Science", "91", "ABH", "D2");
      dt.Rows.Add("Science", "91", "ABI", "D3");
      dt.Rows.Add("English", "191", "ABJ", "D1");
      Label1.Text = ConvertDataTableToHTML(dt);
  
  }
  public static string ConvertDataTableToHTML(DataTable dt)
  {
      string html = "&lt;table border=1&gt;";
      //add header row
      html += "&lt;tr&gt;";
      for (int i = 0; i &lt; dt.Columns.Count; i++)
      {
          html += "&lt;td&gt;" + dt.Columns[i].ColumnName + "&lt;/td&gt;";
      }
      html += "&lt;/tr&gt;";
      //add rows
      string sub = "";
      for (int i = 0; i &lt; dt.Rows.Count; i++)
      {
          html += "&lt;tr&gt;";
          int count = dt.Select("Subject ='" + dt.Rows[i][0].ToString() + "'").Count();
          for (int j = 0; j &lt; dt.Columns.Count; j++)
          {
              if (j &lt; 2)
              {
                  if (sub != dt.Rows[i][0].ToString())
                  {
                      html += "&lt;td rowspan='" + count + "'&gt;" + dt.Rows[i][j].ToString() + "&lt;/td&gt;";
                  }
                  continue;
              }
              html += "&lt;td&gt;" + dt.Rows[i][j].ToString() + "&lt;/td&gt;";
          }
          sub = dt.Rows[i][0].ToString();
          html += "&lt;/tr&gt;";
      }
      html += "&lt;/table&gt;";
      return html;
  }
  </code></pre>
  
  <p>This is the result that I hope</p>
  
  <p><img src="https://i.stack.imgur.com/P9uvo.png" alt="expected result"></p>