I created a LINQ TO SQL project to connect with my database and I’d like to bind a list to a gridview in webforms.
If I add the property Browsable(false) in the designer.cs auto-generated code I can see the column disappear in the gridview.
If I, at the contrary, do something like
namespace InterfacesDAL
{
[MetadataType(typeof(MasterMetadata))]
public partial class InterfacesMasterLog : INotifyPropertyChanging, INotifyPropertyChanged
{
public class MasterMetadata
{
[Browsable(false)]
public int InterfaceLogID;
}
}
}
Column is still showing on the gridview.
How should I fix this?
Checkout this tutorial on data annotations and I would recommend going through the entire MVC EF4 tutorial because it’s great!
http://www.asp.net/mvc/tutorials/mvc-music-store-part-6
GridView doesn’t have good support for Data Annotations. WebGrid (System.Web.Helpers.WebGrid) also doesn’t have complete support for Annotations.
I would suggest using MVCContrib Grid. Below is a good article on how to use it, including how to hide a column automatically
[ScaffoldColumn(false)]http://www.jeremyskinner.co.uk/2010/04/27/mvccontrib-grid-part-7-auto-generated-columns/