I have some code that works fine in an aspx page but I would like to use it in a radwindow.
On the page I have numerous input controls but one of the things is a table that has a button that allowas the user to add another row of inputs. When they hit the button it creates another row in the dynamically created table, but since the rows are created each time I need to reload the old data into the past rows.
The problem is the line
I guess if I could find a way to simply just add a new row to the table on the button push this issue would be solved but have not be able to figure that out yet.
On the page I have numerous input controls but one of the things is a table that has a button that allowas the user to add another row of inputs. When they hit the button it creates another row in the dynamically created table, but since the rows are created each time I need to reload the old data into the past rows.
private void SetPreviousAccountData(int rowsCount) { if (Page.IsPostBack) { Table table = (Table)Page.FindControl("Table1"); if (table != null) { for (int i = 0; i < rowsCount; i++) { //Extracting the Dynamic Controls from the Table DropDownList ddAccount = (DropDownList)table.Rows[i].Cells[1].FindControl("ddAccount" + i + "Col_1"); //Use Request objects for getting the previous data of the dynamic textbox ddAccount.Text = Request.Form["ddAccount" + i + "Col_1"]; TextBox txtProxy = (TextBox)table.Rows[i].Cells[3].FindControl("txtProxy" + i + "Col_3"); //Use Request objects for getting the previous data of the dynamic textbox txtProxy.Text = Request.Form["txtProxy" + i + "Col_3"]; } } } } private void AddAccount(int rowsCount, bool addNewRow) { //Sore the current Rows Count in ViewState if (addNewRow) { rowsCount++; ViewState["AccountRowCount"] = rowsCount; } //Creat the Table and Add it to the Page Table table = new Table(); table.ID = "Table1"; AccountSpan.Controls.Add(table); for (int i = 0; i < rowsCount; i++) { TableRow tRow = new TableRow(); TableCell lblAccountCell = new TableCell(); TableCell tcAccountCell = new TableCell(); TableCell lblProxyCell = new TableCell(); TableCell tcProxyCell = new TableCell(); DropDownList ddAccount = new DropDownList(); TextBox txtProxy = new TextBox(); lblAccountCell.Text = "Account Number:"; lblProxyCell.Text = "Proxy:"; ddAccount.ID = "ddAccount" + i + "Col_1"; txtProxy.ID = "txtProxy" + i + "Col_3"; if (ddClientID.SelectedIndex > 0) { ClientDataContext db = new ClientDataContext(); var query = from p in db.ProxyAccounts where p.ClientID == Int32.Parse(ddClientID.SelectedValue) select new { p.ProxyAccountID, Account = p.NameOnAccount + ": " + p.AccountNumber }; ddAccount.DataSource = query.ToList(); ddAccount.DataTextField = "Account"; ddAccount.DataValueField = "ProxyAccountID"; ddAccount.DataBind(); ddAccount.Items.Insert(0, ""); } tcAccountCell.Controls.Add(ddAccount); tcProxyCell.Controls.Add(txtProxy); tRow.Cells.Add(lblAccountCell); tRow.Cells.Add(tcAccountCell); tRow.Cells.Add(lblProxyCell); tRow.Cells.Add(tcProxyCell); table.Rows.Add(tRow); } SetPreviousAccountData(rowsCount); }The problem is the line
Table table = (Table)Page.FindControl("Table1"); does not find the table.
I guess if I could find a way to simply just add a new row to the table on the button push this issue would be solved but have not be able to figure that out yet.