Hide a column in ASP.NET Dynamic Data

Is there any way to apply an attribute to a model file in ASP.NET Dynamic Data to hide the column?

For instance, I can currently set the display name of a column like this:

[DisplayName("Last name")]
public object Last_name { get; set; }

Is there a similar way to hide a column?

Edit: Many thanks to Christian Hagelid for going the extra mile and giving a spot-on answer 🙂

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Had no idea what ASP.NET Dynamic Data was so you promted me to so some research 🙂

Looks like the property you are looking for is

[ScaffoldColumn(false)]

There is also a similar property for tables
[ScaffoldTable(false)]

source

Method 2

A much, much easier method: If you want to only show certain columns in the List page, but all or others in the Details, etc. pages, see How do I hide a column only on the list page in ASP.NET Dynamic Data?

Simply set AutoGenerateColumns=”false” in the GridView control, then define exactly the columns you want:

<Columns>

<asp:DynamicField DataField=”FirstName” HeaderText=”First Name” />
<asp:DynamicField DataField=”LastName” HeaderText=”Last Name” />
</Columns>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x