vignesh t

vignesh t

  • NA
  • 63
  • 20.3k

Unable to get values of dynamically created controls c#

Jan 8 2018 2:33 AM
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)