SoFunction
Updated on 2025-03-07

C# implements the method of dynamically generating tables

This article shows the method of C# to dynamically generate tables in an example form, and shares it with you for your reference. The specific methods are as follows:

public string CreateTable()
{
  StringBuilder sb = new StringBuilder("");
  int row = 1;//Line Number  if (true )//Is there any data  {
 int nRowCount = 10;//All numbers row = (int)(nRowCount / 5.0);//5.0 indicates how many pieces of data are there per row int colNum = 5;//Number of columns for (int m = 0; m < row; m++)
 {
   //if (m % 2 == 0) //even rows   //{
   // ("<tr class=\"one_tr\">"); // Even line style   //}
   //else //odd row   //{
   // ("<tr class=\"two_tr\">"); //Odd line style   //}
   ("&lt;tr&gt;"); //Additional line count   for (int n = 0; n &lt; colNum; n++)
   {
 ("&lt;td&gt;");
 int currentCount = m * 5 + n;//The current number of items if (currentCount &lt; nRowCount)//Is the current number of pieces within the valid range of the data volume {
   //Add content in the table }
 else
 {
   //Empty   ("&amp;nbsp;");
 }
 ("&lt;/td&gt;");
   }
   ("&lt;/tr&gt;");
 }
  }
  return ();
}

I hope this article will be helpful to everyone's C# programming