Mark Gilbert's Blog

Science and technology, served light and fluffy.

Operation: DataSource Silliness

Remember back to your high school days?  Remember all of those papers that you were required to write – the ones with a minimum page count?  The ones were you proudly turned in a riveting work of literary genius titled “How to write riveting works of literary genius in 5 pages or more”, where margins inexplicably surgedwere tweaked to well beyond their specifications?  Well, my friends, the ASP.NET GridView control has all of us amateurs beat.

Create a web form, and drop a GridView control onto it.  Then, somewhere in the code behind (Page.Load, for example), enter the following:

        Dim xmlA As XmlDocument

        xmlA = New XmlDocument
        xmlA.Load(“test.xml”)

        Me.GridView1.DataSource = xmlA.InnerXml
        Me.GridView1.DataBind()

The “test.xml” file can be any old XML file that you happen to have lying around: the bigger, the better.  It’s times like this that “F5” should be dubbed the “grab on with both hands and hang tight” key:

Item
<
x
m
l
x
m
l
n
s
:
s
=

u
u
i
d
:

B
D
C

And so on, ad nauseam.  Running it produces a GridView with a single column of data, with each row contains a single character from the original XML file.

“You only used 1.2″ margins?!?  Silly freshman…”

Advertisements

April 12, 2007 - Posted by | Visual Studio/.NET

Sorry, the comment form is closed at this time.

%d bloggers like this: