Table tb = new Table();
DynamicControlsHolder.Visible = true;
DynamicControlsHolder.Controls.Add(tb);
TableRow tr = new TableRow();
TextBox txtcntrl = default(TextBox);
TextBox txtcntrl1 = default(TextBox);
Label lblcntrl = default(Label);
TableCell tclbl = default(TableCell);
TableCell tctxt = default(TableCell);
TableCell tctxt1 = default(TableCell);
txtcntrl = new TextBox();
txtcntrl1 = new TextBox();
lblcntrl = new Label();
tclbl = new TableCell();
tctxt = new TableCell();
tctxt1 = new TableCell();
lblcntrl.Text = "Item" + itemid;
txtcntrl.ID = "txtDescription" + itemid;
txtcntrl1.ID = "txtAmount" + itemid;
txtcntrl.Text = rowdetail["itemAmount"].ToString();
txtcntrl.Text = rowdetail["itemDescription"].ToString();
tclbl.Controls.Add(lblcntrl);
tctxt.Controls.Add(txtcntrl);
tctxt1.Controls.Add(txtcntrl1);
tr.Cells.Add(tclbl);
tr.Cells.Add(tctxt);
tr.Cells.Add(tctxt1);
tb.Rows.Add(tr);
tb.Enabled = false;
itemid++;
上面是在服务器端创建2个文本框和标签的代码,append将行添加到表中。
我只需要在最后一行的2个文本框旁边显示一个按钮。如何在服务器端实现此目的
请adivce
答案 0 :(得分:2)
在itemid ++之后;添加此条件
if (itemid == tb.Rows.Count)
{
Response.Write("this is the last row");
}
答案 1 :(得分:1)
在button click event
上,试试这个:
void Button1_Click(Object sender, EventArgs e){
//To append a row :
TableRow addedRow = new TableRow();
tb.Rows.Add(addedRow);
//To add one or more cells to the row:
TableCell addedCell = new TableCell();
addedRow .Cells.Add(addedCell);
}
答案 2 :(得分:1)
而不是
foreach (DataRow rowdetail in customInvoiceDetail.Rows)
使用
for (int i = 1; i <= customInvoiceDetail.Rows.count; i ++)
{
// var rowdetail = customInvoiceDetail.Rows[i];
这样你就可以在for循环结束时检查
if(i == customInvoiceDetail.Rows.count)
// u can add button here