how to insert data in to the data base from a dynamically generated user control

Hi, I am loading one user control dynamically multiple times in a single page inside of an dynamically generated html table row. I am able to load that user contol dynamically multiple times, but the problem is , i want to enter data in the dynamically loaded user control's text boxes and insert the same data in to the database tables. please provide me a simple example to insert data in to the data base from dynamically generated user control. ?

 

The code for dynamically loading an user control which i have written is as follows:

 

using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class NewRequestTable : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { if (ViewState["count1"] == null) ViewState["count1"] = 0; for (int i = 0; i < (int)( ViewState["count1"]); i++) { LoadAmount1(i); } ViewState["count1"] = (int)ViewState["count1"] + 1; } } public string FirstName { get { return txtGrantee.ID; } } protected void savesome(object sender, EventArgs e) { Response.Write("This is Eswar Action"); } protected void LinkButton4_Click(object sender, EventArgs e) { if ((int)ViewState["count1"] == 1) { LoadAmount(); ViewState["count1"] = int.Parse("0") + (int)ViewState["count1"] + 1; } } protected void LoadAmount() { System.Web.UI.HtmlControls.HtmlTableRow tr = new HtmlTableRow();HtmlTableCell tc = new HtmlTableCell(); tc.ColSpan = 2; Control ctl = LoadControl("webUserControle.ascx"); tc.Controls.Add(ctl); tr.Cells.Add(tc); myTable1.Rows.Add(tr); } protected void LoadAmount1(int j) { int txtCount = j + 2; System.Web.UI.HtmlControls.HtmlTableRow tr1 = new HtmlTableRow(); HtmlTableCell tc1 = new HtmlTableCell(); tc1.ColSpan = 2; Control ct2 = LoadControl("webUserControle.ascx"); Label lblLabel = (System.Web.UI.WebControls.Label)ct2.FindControl("txtAmount"); lblLabel.Text = "Amount" + " " + txtCount.ToString(); tc1.Controls.Add(ct2); tr1.Cells.Add(tc1); myTable1.Rows.Add(tr1); } }


eswar reddy
0
eswar_bReddy
1/17/2008 1:05:50 PM
asp.net.ajax_control_toolkit 17816 articles. 1 followers. Follow

1 Replies
981 Views

Similar Articles

[PageSpeed] 42

protected void Page_PreRender(object sender, EventArgs e) 

{

if (ViewState["count1"]!=null&&(int)ViewState["count1"] != 2)

{

HtmlTable ht = (HtmlTable)Page.FindControl("myTable1");foreach (Control ct in ht.Controls)

{

TextBox txt = ct.Controls[0].Controls[0].Controls[0] as TextBox;

if (txt != null)Response.Write("Entered by user" + txt.Text);

}

}

}


Thanks and Regards
Somnath
Please click “Mark as Answer” on the post if it helps you,
0
Som
1/17/2008 2:24:29 PM
Reply: