Binding a GridView to a Generic List of Primitives

Posted Friday, September 21, 2007 3:00 PM by C-Dog's .NET Tip of the Day

I have often bound GridViews to my own custom objects. However today, I needed to bind a GridView to a List<string>. I needed to customize the columns a bit and I soon realized I did not know what to specify as a DataField. I tried Item and just blank but that just did not work. After some quick searching, I found the answer I needed in some community content on the GridView documentation on MSDN. The answer is an explanation point (!). Check out the example below.

<asp:GridView id="MyGridView" runat="server">
       <asp:BoundField id="!" HeaderText="My Primitive" />

That is all there is to it. It doesn't seem to be a very well know fact, so I hope this helps someone.

Read the complete post at

Filed under: