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 //} ("<tr>"); //Additional line count for (int n = 0; n < colNum; n++) { ("<td>"); int currentCount = m * 5 + n;//The current number of items if (currentCount < nRowCount)//Is the current number of pieces within the valid range of the data volume { //Add content in the table } else { //Empty ("&nbsp;"); } ("</td>"); } ("</tr>"); } } return (); }
I hope this article will be helpful to everyone's C# programming