Ok, this is going to be a tricky one to implement.
I'm not entirely sure how you're going to do this... or even if what I'm about to recommend is going work.
I think you're going to have to do is create something to hold the dynamically created controls so that you can reference it later.
I'm going to recommend creating a generic List of Web.UI.Control types:
-
public partial class PO_Insert : System.Web.UI.Page
-
{
-
List<Web.UI.Control> webControlContent;
-
}
Now in your Page Init event you're going to have poll the database in order to dynamically create your controls. Each control that you create you're going to have add to the the generic list and to your page.
For now let's forget the Table all together.
Let's just add the controls as one big mess to the page as we create them.
So in the method that handles the Page Init class you'll have something like:
-
public partial class PO_Insert : System.Web.UI.Page
-
{
-
List<Web.UI.Control> webControlContent;
-
-
private void PO_Insert_Init(Object sender, System.EventArgs e)
-
{
-
//Initializing the generic list of web controls
-
webControlContent = new List<Web.UI.Control>();
-
-
/*
-
Now you need to call the database to figure out
-
what type of controls to create.
-
-
You should look into using Reflection to make this
-
process easier and cleaner.
-
*/
-
-
/*
-
Add the controls to the webControlContent list and
-
also add them Page.
-
-
Make sure to give the controls an ID so that
-
you can access them later.
-
-
You also need to specify any methods used to handle
-
any postback events that the controls may cause.
-
*/
-
-
-
}
-
-
}
You always need to recreate the controls used on the page in the Page Init event.
After the Page Init event they are loaded with the data that was entered by the user. If the control does not exists when ASP.NET is trying to load the data you are going to have problems.
Now that you have your controls available for you to use you can use them:
-
string v1 = "";
-
foreach (Web.UI.Control ctrl in webControlContent )
-
{
-
if(ctrl.ID == "txtCtrl")
-
{
-
TextBox txtCtl = (TextBox) ctrl;
-
v1 = txtCtl.Text;
-
}
-
}