Come da titolo, si dovrebbero estrarre i nomi delle proprietà di una classe e popolare una DropDownList. Qualche idea ?
Come da titolo, si dovrebbero estrarre i nomi delle proprietà di una classe e popolare una DropDownList. Qualche idea ?
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/
prova...sembra promettenteOriginariamente inviato da djciko
Come da titolo, si dovrebbero estrarre i nomi delle proprietà di una classe e popolare una DropDownList. Qualche idea ?
http://www.csharp-examples.net/refle...roperty-names/
Grazie mille, provo e faccio sapere !![]()
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/
Ero incuriosito da questo script e lo provato senza risultati ....
Ho provato anche con quelche webControl ma il problema è sempre lo stesso , il vettore propertyInfos risulta essere vuoto dopo la chimata al metodo GetPropertiescodice:public partial class Default2 : System.Web.UI.Page { public class Persona { public string nome { get; set; } public string cognome { get; set; } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { PropertyInfo[] propertyInfos; propertyInfos = typeof(Persona).GetProperties(BindingFlags.Public | BindingFlags.Static); // sort properties by name Array.Sort(propertyInfos, delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2) { return propertyInfo1.Name.CompareTo(propertyInfo2.Name); }); // write property names gdPropertyInfo.DataSource = propertyInfos; gdPropertyInfo.DataBind(); } } }
![]()
...sostituisci BindingFlags.Static con BindingFlags.InstanceOriginariamente inviato da GabbOne
Ero incuriosito da questo script e lo provato senza risultati ....
codice:............ propertyInfos = typeof(Persona).GetProperties(BindingFlags.Public |BindingFlags.Static); ............![]()
persona.cs
default.aspx.cscodice:using System.Web.UI.HtmlControls; /// <summary> /// Descrizione di riepilogo per Persona /// </summary> public class Persona { public string Nome { get { return "djciko"; } set { } } public string Cognome { get { return "djciko"; } set { } } }
codice:using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Reflection; // <<-------- public partial class reflection_Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { PropertyInfo[] nomiProprieta; nomiProprieta = typeof(Persona).GetProperties(); // Ordinamento Array.Sort(nomiProprieta, delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2) { return propertyInfo1.Name.CompareTo(propertyInfo2.Name); }); // Scrive i nomi delle proprietà foreach (PropertyInfo Info in nomiProprieta) { Response.Write(Info.Name); Response.Write(" "); } } } }![]()
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/
L'ordinamento è opzionale![]()
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/
Non capivo perche nn funzionasse visto che tra i flag avevo messo il binding dei membri public e che tra l'altro questo passaggio di parametri mi è anche nuovo ... ricordo che il simbolo | fosse un semplice or bit a bit e non capisco come questo venisse usato nello script![]()
Non conosco bene C#, sono abituato a VB, ma parla di "Maschera di Bit"
press play on tape
-----
MP3 Listing
https://sourceforge.net/projects/mp3-listing
File Listing
https://sourceforge.net/projects/file-listing-2-0/