Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Values of Dynamic Controls
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00844116
Message ID:
00844143
Vues:
17
>>I have created a form with dynamic controls from a table. I need to collect entered by the users values of these controls and send them to another form.
>>No problem if all controls were text boxes:
>>
>>foreach (Control ctrl in this.Controls)
>>{
>>  MessageBox.Show(ctrl.Text);
>>}
>>
>>However I don't know how to get SelectedValue from a combo box or Checked from a check box controls. These properties are not available in the generic ctrl control. I tried to play with GetProperty():
>>
>>foreach (Control ctrl in this.Controls)
>>{			
>>  if (ctrl.GetType().Name == "ComboBox")
>>   MessageBox.Show(ctrl.GetType().GetProperty("SelectedValue").ToString());
>>}
>>
>>I got System.Object SelectedValue. How can I get the value itself?
>>
>>Thanks in advance
>>
>>Slava
>
>Both of the options that Bonnie and Eric suggest would work. I would go a step furthur if this is a larger project, I would create an interface, and have all of your controls implement that interface, then you could get the values that why by simply casting to the interface and get the value that way.
>
>You might want to try that, it will give you more flexibility down the road.
>
>Morgan

Thank you very much Eric, Bonnie and Morgan. I really appreciate your advice.

Slava
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform