I, wie der Wert dynamisch bevölkerten Kontrollen bekommen
<div id="divNameofParticipants" runat="server">
<asp:Panel ID="panelNameofParticipants" runat="server">
</asp:Panel>
</div>
Ich bin Bestücken der Platte dynamisch aus Code-Behind mit dem folgenden Code conatining ein Panel in aspx Seite ein div haben: Jetzt
void btnSubmitCountParticipant_Click(object sender, EventArgs e)
{
StringBuilder sbparticipantName=new StringBuilder();
try
{
int numberofparticipants = Convert.ToInt32(drpNoofparticipants.SelectedValue);
ViewState["numberofparticipants"] = numberofparticipants;
Table tableparticipantName = new Table();
int rowcount = 1;
int columnCount = numberofparticipants;
for (int i = 0; i < rowcount; i++)
{
TableRow row = new TableRow();
for (int j = 0; j < columnCount; j++)
{
TableCell cell = new TableCell();
TextBox txtNameofParticipant = new TextBox();
txtNameofParticipant.ID = "txtNameofParticipant" + Convert.ToString(i);
cell.ID = "cell" + Convert.ToString(i);
cell.Controls.Add(txtNameofParticipant);
row.Cells.Add(cell);
}
tableparticipantName.Rows.Add(row);
panelNameofParticipants.Controls.Add(tableparticipantName);
}
}
catch(Exception ex)
{
}
}
Ich möchte auf den Wert dieser dynamisch generierten Textbox im Codebehind zugreifen. Für den i ist mein Code wie folgt:
aber ich bin nicht in der Lage, die Werte im Codebehind zu erhalten.
TextBox txtParticipantName = (TextBox)panelNameofParticipants.FindControl(findcontrol);
der obige Code ist auch nicht in der Lage, die Kontrolle und es ist immer zu finden null geben .Was mache ich wrong.i die Steuerelemente im Laden der Seite neu erstellt, da Postbacks staatenlos ist, aber immer noch kein Erfolg.
Vielen Dank im Voraus
das Problem auf die Erstellung dynamischer Kontrollen in Server-Seite ist müssen Sie sie auf jeder Seite Initialisierung neu erstellen, wenn im nicht wron g, OnInit-Methode. – Sherlock
sind Sie offen für etwas wie die Gridview? es wird Ihnen eine Last von Codierung sparen – naveen
Dies könnte helfen: http://geekswithblogs.net/shahed/archive/2008/06/26/123391.aspx – sr28