asp.net动态添加table 行

后台动态添加

  string[] strs = __option.Value.ToString().Split(';');
        for (int i = 0; i < strs.Length - 1; i++)
        {
            HtmlTableRow row = new HtmlTableRow();
            HtmlTableCell textCell = new HtmlTableCell();
            textCell.Style.Add("width", "40px");
            textCell.Style.Add("align", "right");
            textCell.InnerHtml = "<span>内&nbsp;容:</span>";

            HtmlTableCell textCell1 = new HtmlTableCell();
            textCell1.Style.Add("width", "50px");
            textCell1.Style.Add("align", "left");
            textCell1.InnerHtml = "<input class=\"tbTitle\" value=\"" + strs[i].Split('|')[0] + "\" style=\"width: 45px;\" type=\"text\" />";

            HtmlTableCell textCell2 = new HtmlTableCell();
            textCell2.Style.Add("width", "40px");
            textCell2.Style.Add("height", "30px");
            textCell2.InnerHtml = "<span>分&nbsp;值:</span>";

            HtmlTableCell textCell3 = new HtmlTableCell();
            textCell3.Style.Add("width", "30px");
            textCell3.Style.Add("align", "left");
            textCell3.InnerHtml = "<input class=\"tbScore\" value=\"" + strs[i].Split('|')[1] + "\" style=\"width: 25px;\" type=\"text\" />";

            HtmlTableCell textCell4 = new HtmlTableCell();
            textCell4.Style.Add("width", "30px");
            textCell4.Style.Add("align", "left");
            textCell4.InnerHtml = "<a class=\"bTaDelete\" onclick=\"DeleteRows(this)\" href=\"#\">×</a>";

            row.Cells.Add(textCell);
            row.Cells.Add(textCell1);
            row.Cells.Add(textCell2);
            row.Cells.Add(textCell3);
            row.Cells.Add(textCell4);

            bTable.Rows.Add(row);
        }

前台动态生成

 function OptionAdd() {
            var rownum = $("#bTable tr").length;
            var table = $("#bTable")[0];
            var row;
            if (rownum == 0) {
                row = table.insertRow(0);
            } else {
                row = table.insertRow(rownum);
            }
            var textCell = row.insertCell(0);
            textCell.setAttribute("width", "40px");
            textCell.setAttribute("align", "left");
            var textCell1 = row.insertCell(1);
            textCell.setAttribute("width", "50px");
            textCell.setAttribute("align", "left");
            var textCell2 = row.insertCell(2);
            textCell.setAttribute("width", "40px");
            textCell.setAttribute("height", "30px");
            var textCell3 = row.insertCell(3);
            textCell.setAttribute("width", "30px");
            textCell.setAttribute("align", "left");
            var textCell4 = row.insertCell(4);
            textCell.setAttribute("width", "30px");
            textCell.setAttribute("align", "left");

            textCell.innerHTML = "<span>&nbsp;容:&nbsp;&nbsp;</span>";
            textCell1.innerHTML = "<input class=\"tbTitle\" style=\"width: 45px;\" type=\"text\" />";
            textCell2.innerHTML = "<span>&nbsp;值:</span>";
            textCell3.innerHTML = "<input class=\"tbScore\" style=\"width: 25px;\" type=\"text\" />";
            textCell4.innerHTML = "<a class=\"bTaDelete\" onclick=\"DeleteRows(this)\" href=\"#\">×</a>";
        }

 

posted @ 2014-08-15 16:06  张国朋  阅读(1303)  评论(0)    收藏  举报