I have some experience in developing business logic and database logic and primarily work with C#. Now I would like to build my first data-driven presentation-tier in ASP.NET. I was just wondering how I should fill my DataGrids with data.
I have IList – Collections of business entities such as “Customer” which I retrieve from my BLL. It is easy to bind the whole collection to a control, but that means, that all public properties of my business entities are shown as columns. I cannot decide which properties to show, how they should be ordered and how they should be displayed (e.g. DateTime as ShortTimeString).
Could you please tell me where to find best-practise examples or tell me how you solved this problem?
Best regards,
Daniel Lang
Whenever I bind to grid I make sure to always have the property
AutoGenerateColumns = false. I then explicitly define the columns and templates I use.I think this is best practice since the next coder might come along and add something to your object and not realize it is going to automatically be added to everywhere you bind it to a grid. It also makes you consider each field to see if they really need to see it as is or with some type of template.
The AutoGenerateColumns property is one of those features that looks really cool in demos but in the real world is not that useful and can lead to unexpected issues.