Bind (SP)Gridview field to generic list of strings

21 Jun

Probably this is my lack of knowledge in the (sp)gridview area, but I want to share it anyway.

I realized I always bound gridviews to custom objects only. Recently I wanted to bound a generic list of strings (List<string>) to a field in a gridview and didn’t know how to accomplish this. After trying a few options and some searching I found the answer:
An exclamation mark: !

Example:

BoundField field = new BoundField();
field.DataField = "!";

Never thought of this one myself.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.