[RESOLVED]Prevent a property from a custom object from being generated automatically in gridview/formview

Is there was way to prevent a gridview/formview from autogenerating certain properties from a databound custom object?

example:

public class Demo

{

public string property1 { get{return "";}}

public string property2 { get{return "";}}

//don’t want this property to be created automatically when i select my datasource on a ASP.NET formview/gridview.

//i do want property1 and property2 to be generated automatically.

public string property3 { get{return "";}}

}

Datatsource is a List<Demo> that can contain 0 to n records.

hi Rollabone,

According to your description, if you ony want property1 and property2 to be generated automatically

i think that the best way to set property3 as private, as shown below:

private string property3 { get { return ""; } }

if you need the property3 which must be public, i would you can’t ony want property1 and property2 to be generated automatically, you have to use

<asp:TemplateField HeaderText="property1"> <ItemTemplate>...

Hope it helps you.

 

Hope it helps you.

GridView and DetailsView will generate a field for each public property of the object. If you can’t set property3 private, then you can’t use autogenerate, and should specify fields explicitly.

Leave a Reply