2
Answers

Unable to get values of dynamically created controls c#

Photo of vignesh t

vignesh t

7y
137
1
I have created dynamic controls on button click and I'm not able to retrieve values of dynamically created controls. I am getting values of dynamic controls inside a panel.
 
pnlDepartment is the Panel ID.
  1. protected void btnValues_Click(object sender, EventArgs e)  
  2. string strDDLValue = string.Empty;  
  3. foreach (DropDownList ddl in pnlDepartment.Controls.OfType<DropDownList>())  
  4. {  
  5. strDDLValue = ddlName.SelectedItem.Text + "," + ddlLocation.SelectedItem.Text;  
  6. }  
  7. }  
The strDDLValue has only first dropdown values and when it loops for the second time it still takes the first dropdown values and unable to get dynamic control values.
 
Please correct me if I'm making a mistake somewhere.

Answers (2)

0
Photo of vignesh t
NA 31 861 7y
I'm creating two dynamic dropdown controls inside a panel and I'm unable to get values of dynamically created control values.
0
Photo of Amit Gupta
NA 16.5k 25.7k 7y
strDDLValue = ddlName.SelectedItem.Text + "," + ddlLocation.SelectedItem.Text
 
ddlName and ddlLocation is not the same variable that are declared on the loop.