现在Table里增加一行,假如第一次增加后为2行.
再一次增加时,Table里还是1行,而不是2行。请高手们指正
TextBox itemNew = new TextBox();
itemNew.ID = "ReportItem" + Convert.ToInt32(ViewState["ItemCount"]);
itemNew.Report_OnDel += new ReportItem.DelReort(itemCurrent_Report_OnDel);TableCell cell = new TableCell();
cell.Controls.Add(itemNew);TableRow row = new TableRow();
row.Cells.Add(cell);
再一次增加时,Table里还是1行,而不是2行。请高手们指正
TextBox itemNew = new TextBox();
itemNew.ID = "ReportItem" + Convert.ToInt32(ViewState["ItemCount"]);
itemNew.Report_OnDel += new ReportItem.DelReort(itemCurrent_Report_OnDel);TableCell cell = new TableCell();
cell.Controls.Add(itemNew);TableRow row = new TableRow();
row.Cells.Add(cell);
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dynamicAdd.aspx.cs" Inherits="WebApp.dynamicAdd" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript">
function addFile() {
var _table = document.createElement("table");
var _tbody = document.createElement("TBODY");
var _row;
var _cell;
var rlen = parseInt(document.getElementById("rowlen").value);
for (var i = 0; i < rlen; i++) {
_row = document.createElement("tr");
for (var j = 0; j < 3; j++) {
_cell = document.createElement("td");
var div = document.createElement("div");
var f = document.createElement("input");
f.setAttribute("type", "text")
f.setAttribute("name", "txtCardNo")
f.setAttribute("size", "20")
div.appendChild(f)
var d = document.createElement("input");
d.setAttribute("type", "button")
d.setAttribute("onclick", "deteFile(this)");
d.setAttribute("value", "移除")
div.appendChild(d)
_cell.appendChild(div);
_row.appendChild(_cell);
}
_tbody.appendChild(_row);
}
_table.appendChild(_tbody);
var con = document.getElementById("_container");
con.innerHTML = "";
con.appendChild(_table);
} function deteFile(o) {
while (o.tagName != "DIV") o = o.parentNode;
o.parentNode.removeChild(o);
} function getAllTd() {
document.getElementsByTagName("td")[0].style.backgroundImage = 'url(http://img.baidu.com/img/logo-zhidao.gif)';
}
</script></head>
<body>
<form id="form1" runat="server">
<select id="rowlen">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input value="add" type="button" onclick="addFile()" />
<div id="_container">
</div>
<input type="button" value="ok" onclick="getAllTd()" />
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dynamicAdd.aspx.cs" Inherits="WebApp.dynamicAdd" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript">
function addFile() {
var _table = document.createElement("table");
var _tbody = document.createElement("TBODY");
var _row;
var _cell;
var rlen = parseInt(document.getElementById("rowlen").value);
for (var i = 0; i < rlen; i++) {
_row = document.createElement("tr");
for (var j = 0; j < 3; j++) {
_cell = document.createElement("td");
var div = document.createElement("div");
var f = document.createElement("input");
f.setAttribute("type", "text")
f.setAttribute("name", "txtCardNo")
f.setAttribute("size", "20")
div.appendChild(f)
var d = document.createElement("input");
d.setAttribute("type", "button")
d.setAttribute("onclick", "deteFile(this)");
d.setAttribute("value", "移除")
div.appendChild(d)
_cell.appendChild(div);
_row.appendChild(_cell);
}
_tbody.appendChild(_row);
}
_table.appendChild(_tbody);
var con = document.getElementById("_container");
con.innerHTML = "";
con.appendChild(_table);
} function deteFile(o) {
while (o.tagName != "DIV") o = o.parentNode;
o.parentNode.removeChild(o);
} function getAllTd() {
document.getElementsByTagName("td")[0].style.backgroundImage = 'url(http://img.baidu.com/img/logo-zhidao.gif)';
}
</script></head>
<body>
<form id="form1" runat="server">
<select id="rowlen">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input value="add" type="button" onclick="addFile()" />
<div id="_container">
</div>
<input type="button" value="ok" onclick="getAllTd()" />
</form>
</body>
</html>protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
if (!string.IsNullOrEmpty(Request["txtCardNo"])) {
string[] strCardes = Request["txtCardNo"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string strCard in strCardes) {
//to do
}
}
}
}