zoukankan      html  css  js  c++  java
  • 动态生成表格 C#

     public string CreateTable()
            {

               
                StringBuilder sb = new StringBuilder("");
                int row = 1;//行数
               
                if (true )//是否有数据
                {
                    int nRowCount = 10;//所有条数

                    row = (int)Math.Ceiling(nRowCount / 5.0);//5.0表示每行有多少条数据
                    int colNum = 5;//列数

                    for (int m = 0; m < row; m++)
                    {
                        //if (m % 2 == 0)    //偶数行
                        //{
                        //    sb.Append("<tr class=\"one_tr\">"); //偶数行样式
                        //}
                        //else   //奇数行
                        //{
                        //    sb.Append("<tr class=\"two_tr\">"); //奇数行样式
                        //}

                        sb.Append("<tr>"); //加行数


                        for (int n = 0; n < colNum; n++)
                        {


                            sb.Append("<td>");
                            int currentCount = m * 5 + n;//当前所处条数

                            if (currentCount < nRowCount)//当前所处条数是否在数据量的有效范围内
                            {
                              
                                //添加表格内的内容
                            }
                            else
                            {
                                //置空
                                sb.Append("&nbsp;");
                            }

                            sb.Append("</td>");
                        }

                        sb.Append("</tr>");

                    }

                }

                return sb.ToString();

            }

  • 相关阅读:
    JZOJ3404[NOIP2013模拟]卡牌游戏(2019.08.04[NOIP提高组]模拟 B 组T2)
    JZOJ3403[NOIP2013模拟]数列变换(2019.08.04[NOIP提高组]模拟 B 组T1)
    Luogu1169BZOJ1057[ZJOI2007]棋盘制作
    BZOJ1867[Noi1999]钉子和小球
    Luogu2524 Uim的情人节礼物
    error: Failed dependencies:解决
    Android 通知 相关api记录
    LitePal 之 DatabaseGenerateException
    Button重写onClick两种方式
    【洛谷3948】数据结构
  • 原文地址:https://www.cnblogs.com/luluping/p/1201290.html
Copyright © 2011-2022 走看看