datagrid

A

A.J

hi ppl,

while going through the threads i came to know tat we can populate the
datagrid with xml.Is this mean tat we can populate dr with XML of any
format.(This concept is bit new for me;could you please explain wat
kind of xml can be populated in a DG)ex:
(*Sorry got to ask the Q again)

<weather-report>
<date>March 25, 1998</date>
<time>08:00</time>
- <area>
<city>Seattle</city>
<state>WA</state>
<region>West Coast</region>
<country>USA</country>
</area>
- <measurements>
<skies>partly cloudy</skies>
<temperature>46</temperature>
- <wind>
<direction>SW</direction>
<windspeed>6</windspeed>
</wind>
<h-index>51</h-index>
<humidity>87</humidity>
<visibility>10</visibility>
<uv-index>1</uv-index>
</measurements>
</weather-report>
 
W

W.G. Ryan - MVP

Any XML can conceivably turned into something that will go in a grid.
However the format of the XML will dictate how it looks in the grid. The
best way to know what the default behavior will be is take your XML file and
do a DataSet.ReadXML(YourFileName);

Now this will tell you what is being recognized as an element, attribute
etc. This format may be what you want and you can just bind your DataGrid
to this dataset. But it may not. So you may need to format the XML
differently. In this case, you can use XSLT to make your original XML look
like the XML that will be needed to populate your grid and make it look
right.

First, do a
DataSet ds = new DataSet();
ds.ReadXml(@"C:\YourFileNameWithXML.txt");

First see if it will parse. You may need a root node in order for this to
work. Then call

DataGrid.DataSource = ds;

Now you'll see what it will look like by default. That XML below probably
won't look like anything you want by default. It may not even open into a
DataSet. If not, then you'll need to read it in with an XmlDocument class or
use Xslt to format the XML to a dataset that will display how you want it
to.

I know you're new so I'll walk you through this, but does this much make
sense? If not, i'll try to walk through it again. If so, lemme know what
the Grid looks like (it may be fine - it depends on your needs) after
running the above code.

Cheers,

Bill
 
W

W.G. Ryan - MVP

Sure thing. And if the XML isn't ok and you need to use XSLT, let me know, I
can probably help you out there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top