Thursday, 26 July 2007

Gridview

Was looking for a way to populate a Gridview with a simple array of strings, and everybody and their dog seems to be posting tutorials about doing it with SQL data sources, etc (Or maybe I'm just really hopeless at Googling information I need). And then I found this gem of a guide on Gridview by Mike Pope. Turns out the feature I needed is apparently undocumented (go figure), and if you go over to his site here, you'll find, in his words:

"Sometimes your life is even simpler -- you have an array with simple values in it, and you want to display those. It's easy enough to bind the grid to the array. But how do you bind a BoundField to the contents of the array element? Turns out that if you set the DataField property of a BoundField to !, it tells the field (column) to get the ToString() version of whatever's in the array. (I'm pretty sure this is undocumented, though perhaps not unknown.)"

Isn't life great when it's simple?

No comments: