带有标签和按钮作为列的动态表

时间:2015-01-13 05:15:08

标签: c# html asp.net .net

我想在C#中创建一个动态表格,动态Adding and deleting of row我需要two columnsColumn 1 as labelcolumn 2 as button,我希望该表添加来自其他一些方法..

并单击第2列的按钮,我希望特定行只能删除.. 例如:

COL1      COL2

label     button(to delete row)

(添加)

我正在尝试的是: 在aspx中

 <asp:Table border="1" id="Table1" runat="server">
 </asp:Table>

在C#中

  for (int i = 0; i < 3; i++)
        {
            TableRow row = new TableRow();
            for (int j = 0; j <2; j++)
            {
                TableCell cell = new TableCell();

                // Add the control to the TableCell

                LinkButton tb1 = new LinkButton();

                if (IsOdd(j))
                {
                    Label tb = new Label();
                    tb.Width = 100;

                    // Set a unique ID for each zTextBox added
                    tb.ID = "TextBoxRow_" + i + "Col_" + j;
                    tb.Text = "asdad";
                    cell.Controls.Add(tb);

                }
                else
                {
                    tb1.Width = 100;

                    // Set a unique ID for each zTextBox added
                    tb1.ID = "TextBoxRow_" + i + "Col_" + j;
                    tb1.Text = "asdad";
                    cell.Controls.Add(tb1);
                }
                // Add the TableCell to the TableRow
                row.Cells.Add(cell);
            }
   Table1.Rows.Add(row);

        }

0 个答案:

没有答案