Hello All,
I am using Visual Studio 2010, and developing a web project. My requirement is to add controls to web page dynamically. I have added the controls and those are displaying properly on the web page.
But when I am trying to read values from the controls, I am unable to find the controls.
Below is the sample code.
int i;
TableCell tcSNum;
i = 0;
foreach (DataRow drStudent in dsStudent.Tables[0].Rows)
{
tr = new TableRow();
tr.BorderColor = System.Drawing.Color.Blue;
tcSNum = new TableCell();
tcSNum.ID = "TCNUM" + i.ToString();
lblSName = new Label();
lblSName.ID = "LBLSNAME" + i.ToString();
lblSName.Text = drStudent["StudentName"].ToString();
tcSNum.Controls.Add(lblSNum);
tr.Cells.Add(tcSNum);
t.Rows.Add(tr);
i++;
}
this.pnl.Controls.Add(t);
Below code to find controls in the Panel
for(int i = 0;i<numberofStudents;i++)
{
Label lblrno = (Label)pnl.FindControl("LBLSNAME" + i.ToString());
Response.Write(lblrno.Text);
}
Please help me in this regard.
Thanks in advance
Thanks & Regards Prasad DVR