0

我创建了两个动态表和文本框,如下所示:

protected void drpNetworkList_SelectedIndexChanged(object sender, EventArgs e)
    {
     string socialNetworkName = drpNetworkList.SelectedItem.Text;

DataSet networkdata =   VoCServiceObj.GetSocailNetworkNameDetails(partnerid,socialNetworkName);           

        int cdount = networkdata.Tables[0].Rows.Count;

            pnlViewData.Controls.Clear();
            Check.Checked = true;               
            pnlViewData.Visible = true;
            table = new Table();
            table.ID = "tbl_dy";

            //Brandurl
            row = new TableRow();
            cell = new TableCell();

            Label lbl = new Label();
            lbl.ID = "lbl_1";
            lbl.Text = "BrandURL";
            cell.Controls.Add(lbl);
            row.Cells.Add(cell);

            cell = new TableCell();
            TextBox txt = new TextBox();
            txt.ID = "textBox";
            txt.Text = networkdata.Tables[0].Rows[0]["BrandDestinationURL"].ToString();
            cell.Controls.Add(txt);
            row.Cells.Add(cell);
            table.Rows.Add(row);

            for (int i = 1; i <= cdount; i++)
            {
                int count = i - 1;

                //ProdutId
                row = new TableRow();
                cell = new TableCell();

                Label lbl2 = new Label();
                lbl2.ID = "lbl_1'" + i + "'";
                lbl2.Text = "ProductID" + i + "'";
                cell.Controls.Add(lbl2);
                row.Cells.Add(cell);

                cell = new TableCell();
                TextBox txt2 = new TextBox();
                txt2.ID = "textBox1" + i + "'";
                txt2.Text = networkdata.Tables[0].Rows[count]["ProductID"].ToString();
                cell.Controls.Add(txt2);
                row.Cells.Add(cell);

                table.Rows.Add(row);

                //ProdutURL
                row = new TableRow();
                cell = new TableCell();

                Label lbl3 = new Label();
                lbl3.ID = "lbl_2'" + i + "'";
                lbl3.Text = "ProductURL" + i + "'";
                cell.Controls.Add(lbl3);
                row.Cells.Add(cell);

                cell = new TableCell();
                TextBox txt3 = new TextBox();
                txt3.ID = "textBox2" + i + "'";
                txt3.Text = networkdata.Tables[0].Rows[count]["ProductDestinationURL"].ToString();
                cell.Controls.Add(txt3);
                row.Cells.Add(cell);

                table.Rows.Add(row);

            }
            pnlViewData.Controls.Add(table);

    }
   protected void imgSave_Click(object sender, ImageClickEventArgs e)
    {
                    TextBox tb1 = (TextBox)Page.FindControl("textBox11");
        String str = string.Empty;
        str = tb1.Text;
    }

文本框显示来自数据库的默认值。我在运行时编辑这些值,我想在按钮单击函数中获取这些值。我如何做到这一点???

提前致谢!!

4

1 回答 1

0

每次创建页面时都会创建所有页面控件。

在事件上动态创建的控件必须在下一个Init.

只有之前创建的控件ProcessPostData才能接收用户输入的数据。

您可以使用ViewState记住下次必须重新创建这些控件。

于 2012-09-19T08:15:53.840 回答