这样一个页面,有三行,每行有四个输入项,我是用表格,然后每个表格里加了一个textbox但有可能三行不够,这时候有一个按钮,点一下,增加一行,不知道怎么实现?还是这个问题,用下面代码实现了,但是怎么在服务器端取得用 户输入的值?
我不用JS,所以还得问,给点代码?谢!<html>
<head>
<script language=javascript>
var count = 0;
function addRow()
{
count++;
var objTable = document.all.mytable;
var row1 = objTable.insertRow();
var col1 = row1.insertCell(0);
col1.setAttribute("rowspan", 2, 0);
col1.innerText = count;
var col2 = row1.insertCell();
col2.innerHTML = "<input type=text size=20 >";
var col3 = row1.insertCell();
col3.innerHTML = "<input type=text size=20 >";
var row2 = objTable.insertRow();
var col4 = row2.insertCell();
col4.innerHTML = "<input type=text size=20 >";
var col5 = row2.insertCell();
col5.innerHTML = "<input type=text size=20 >";
}</script>
</head>
<body>
<table border=1 id="mytable">
<tr><td rowspan="2" title="Name">NO</td><td width="100">name</td><td width="100">age</td></tr>
<tr><td width="100">qq</td><td width="100">mail</td></tr>
</table>
<table>
<tr>
<td><input type=button value="Add Row" style="width:100px;heigh:50px" onclick="addRow()"></td>
<td><input type=button value="Del Row" style="width:100px;heigh:50px" onclick="delRow()"></td>
</tr>
</table>
</body>
</html>
我不用JS,所以还得问,给点代码?谢!<html>
<head>
<script language=javascript>
var count = 0;
function addRow()
{
count++;
var objTable = document.all.mytable;
var row1 = objTable.insertRow();
var col1 = row1.insertCell(0);
col1.setAttribute("rowspan", 2, 0);
col1.innerText = count;
var col2 = row1.insertCell();
col2.innerHTML = "<input type=text size=20 >";
var col3 = row1.insertCell();
col3.innerHTML = "<input type=text size=20 >";
var row2 = objTable.insertRow();
var col4 = row2.insertCell();
col4.innerHTML = "<input type=text size=20 >";
var col5 = row2.insertCell();
col5.innerHTML = "<input type=text size=20 >";
}</script>
</head>
<body>
<table border=1 id="mytable">
<tr><td rowspan="2" title="Name">NO</td><td width="100">name</td><td width="100">age</td></tr>
<tr><td width="100">qq</td><td width="100">mail</td></tr>
</table>
<table>
<tr>
<td><input type=button value="Add Row" style="width:100px;heigh:50px" onclick="addRow()"></td>
<td><input type=button value="Del Row" style="width:100px;heigh:50px" onclick="delRow()"></td>
</tr>
</table>
</body>
</html>
前台:
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 176px; POSITION: absolute; TOP: 80px" cellSpacing="1"
cellPadding="1" width="300" border="1" runat="server">
<TR>
<TD>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></TD>
<TD>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox></TD>
<TD>
<asp:TextBox id="TextBox3" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>
<asp:TextBox id="TextBox4" runat="server"></asp:TextBox></TD>
<TD>
<asp:TextBox id="TextBox5" runat="server"></asp:TextBox></TD>
<TD>
<asp:TextBox id="TextBox6" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>
<asp:TextBox id="TextBox7" runat="server"></asp:TextBox></TD>
<TD>
<asp:TextBox id="TextBox8" runat="server"></asp:TextBox></TD>
<TD>
<asp:TextBox id="TextBox9" runat="server"></asp:TextBox></TD>
</TR>
</TABLE>
<TABLE id="Table2" style="Z-INDEX: 102; LEFT: 248px; POSITION: absolute; TOP: 192px" cellSpacing="1"
cellPadding="1" width="300" border="1">
<TR>
<TD>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD>
<asp:Button id="Button2" runat="server" Text="Button"></asp:Button></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
</form>
后台:
private void Button1_Click(object sender, System.EventArgs e)
{
int numrows=2;
int numcells=3;
for (int j=0; j<numrows; j++)
{
HtmlTableRow newRow = new HtmlTableRow();
for (int i=0; i<numcells; i++)
{
HtmlTableCell newCell = new HtmlTableCell();
newCell.Controls.Add(new LiteralControl("行 " + j.ToString() + ":"));
TextBox newControl = new TextBox();
newControl.Text = "单元格 " + i.ToString();
newControl.ID=j.ToString();
newCell.Controls.Add(newControl);
newRow.Cells.Add(newCell);
}
Table1.Rows.Add(newRow);
} } private void Button2_Click(object sender, System.EventArgs e)
{
string ss="1";
for(int i=0;i<Table1.Rows.Count;i++)
{
for(int j=0;j<3;j++)
{
TextBox myTxt=new TextBox();
myTxt=(TextBox)Table1.FindControl("Textbox1");
ss=myTxt.Text.ToString();
Response.Write(ss);
}
}
}