I have a usercontrol and I want to create some instance by a loop in my web form. Everything is OK, but all of instances show same data (Data of last instance)!
My code is: (My usercontrol is: WebUserControl)
MyDataSet.tblMyDataTable oTable = new MyDataSet.tblMyDataTable();
MyDataSetTableAdapters.tblMyTableAdapter oAdapter
= new MyDataSetTableAdapters.tblMyTableAdapter();
oAdapter.Fill(oTable);
for (int i = 0; i < oTable .Count; i++)
{
Context.Items["ID"] = oTable[i].ID;
WebUserControl newControl = new WebUserControl();
newControl = (WebUserControl)LoadControl("~/WebUserControl.ascx");
newControl.ID = "myControl" + i.ToString();
System.Web.UI.HtmlControls.HtmlTableRow newRow
= new System.Web.UI.HtmlControls.HtmlTableRow();
System.Web.UI.HtmlControls.HtmlTableCell newCell
= new System.Web.UI.HtmlControls.HtmlTableCell();
newCell.Controls.Add(newControl);
newRow.Controls.Add(newCell);
myTable.Rows.Insert(0, newRow);
}
In the event of Page_Load in my uercontrol, my code is:
myID = (string)Context.Items["ID"].ToString().Clone();
ShowNewsSummary(myID);
That ShowNewsSummary is a function that fills fields of usercontrol.
Thanks.