BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Is there a way to use "Data Annotation - Properties" to populate the DataGridView without having to set column name?
Ex:
[Column("First Name")] public string FirstName { get; set; } [Column("Last Name")] public string LastName { get; set; }
Using System.ComponentModel.DataAnnotations;
[Display(Name = "Category Name")]
public string CategoryName
{
get
{
return this.cat_Name;
}
set
{
this.cat_Name = value;
}
}
Data d = new Data();
foreach (GridBoundColumn column in columns)
{
var col = (d.GetType().GetProperty(column.MappingName)).GetCustomAttributes(typeof(DisplayAttribute), true);
if (col is DisplayAttribute[] && (col as DisplayAttribute[]).Count() > 0)
{
string headerText = (col as DisplayAttribute[])[0].Name;
column.HeaderText = headerText;
}
} |
Thanks... it Works =)