我有一個ASP:表中有一行的單元格,我需要能夠添加一行到這個通過點擊添加按鈕,在結尾重複現有的行。添加重複的行和列OnClick c#
我的表碼
<asp:Table ID="Table1" runat="server" Height="50%" Width="100%">
<asp:TableHeaderRow CssClass="lblrow2" HorizontalAlign="Left" BackColor="AliceBlue">
<asp:TableHeaderCell ID="haccountref">Account Ref:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hproduct">Product</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hqty">Qty:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hunitprice">Unit Price:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="hdiscount">Discount:</asp:TableHeaderCell>
<asp:TableHeaderCell ID="htotal">Total Line Amount:</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow CssClass="r1">
<asp:TableCell><asp:TextBox ID="vaccountref" ReadOnly="True" runat="server"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:DropDownList runat="server" ID="vproduct"></asp:DropDownList></asp:TableCell>
<asp:TableCell><input id="Qty" type="text" /></asp:TableCell>
<asp:TableCell><input id="Unit Price" type="text" /></asp:TableCell>
<asp:TableCell><input id="Discount" type="text" /></asp:TableCell>
<asp:TableCell><input id="Total" type="text" /></asp:TableCell>
<asp:TableCell><input id="Button1" type="image" src="plusButton.png" value="button" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
我的C#代碼後面 - 我沒有得到任何錯誤,但沒有重複的行
protected void Button1_Click(object sender, System.EventArgs e)
{
// Total number of rows.
int rowCnt;
// Current row count.
int rowCtr;
// Total number of cells per row (columns).
int cellCtr;
// Current cell counter
int cellCnt;
rowCnt = int.Parse(TextBox1.Text);
cellCnt = int.Parse(TextBox2.Text);
for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
{
// Create new row and add it to the table.
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
{
// Create a new cell and add it to the row.
TableCell tCell = new TableCell();
tCell.Text = "Row " + rowCtr + ", Cell " + cellCtr;
tRow.Cells.Add(tCell);
}
}
}
你嘗試把這個線 - Table1.Rows.Add(特羅);當你完成了向該行添加單元格的操作後,即將其作爲最後一行放在你的外觀中 – 2011-03-29 12:04:37
@ Subhash-Dike這可以工作,但是我想複製已經安裝的整行,以便用戶可以輸入另一行文本在行添加,但只有文本這裏的想法是,用戶可以填寫一個訂單列表,然後提交到一個SQL Tabl – 2011-03-29 12:23:37