473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

DataGrid support for XML with different node types

Hello,

I have xml like this....

<test>
<question>sdfsa</question>
<section><question>43ga</question>
<question>asdf</question>
</test>

I make and xsd file with
<xs:all>
<xs:element....
<xs:element....
</xs:all>

I then bind the XML to a DataGrid...

DataGrid.DataSource = DataSet;
DataGrid.DataBind();

but I only get the questions, I notice there is a DataMember property
I can set to DataGrid.DataMember = "Section"; and I will get that one,
but essential I want a table with both elements in there...

Is there anyway to do this...?

Thank You
Nov 12 '05 #1
2 3233
Hi Magister

Try creating a DataSet in Visual Studio .NET using the design time
environment - you will see that if you create an element, then add a couple
of 'fields' to it, then the structure you get in the xsd looks a bit like
this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Test" targetNamespace="http://tempuri.org/Test.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/Test.xsd"
xmlns:mstns="http://tempuri.org/Test.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Test" msdata:IsDataSet="true">
<xs:complexType>
<xs:all>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="Question" type="xs:string" minOccurs="0" />
<xs:element name="Answer" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

Then you can bind to the Question and Answer 'columns' by setting the
DataSource. Essentially the XML data needs to look more table like to work
the way that you want, with a root element representing the table, top level
element children of the root representing rows, and grand children of the
root representing columns.

HTH

Nigel

"magister" wrote:
Hello,

I have xml like this....

<test>
<question>sdfsa</question>
<section><question>43ga</question>
<question>asdf</question>
</test>

I make and xsd file with
<xs:all>
<xs:element....
<xs:element....
</xs:all>

I then bind the XML to a DataGrid...

DataGrid.DataSource = DataSet;
DataGrid.DataBind();

but I only get the questions, I notice there is a DataMember property
I can set to DataGrid.DataMember = "Section"; and I will get that one,
but essential I want a table with both elements in there...

Is there anyway to do this...?

Thank You

Nov 12 '05 #2
Thanks for getting back to me, the thing is that I am binding to a
hierarchical grid control....I am using attributes as columns...

<test>
<question Type="Selection" Text="What is the capital of the USA">
<option Text="Texas" />
<option Text="DC" />
</question>
<section Type="Random" Text="Here is a section about France" >
<question Type="Selection" Text="What is the capital of the
France">
<option Text="Paris" />
<option Text="Lyon" />
</question>
<question Type="Input" Text="Type in the major language spoken in
France">
</section>
<question Type="Input" Text="Type in the major language spoken in
the USA">
<question Type="Selection" Text="What is the capital of the UK">>
<option Text="London" />
<option Text="Manchester" />
</question>
</test>

I wanteded to bind the columns of question and section in the first
level of the hierarchical grid as they have similar attribute columns,
but when I get my typed Dataset Section and Question are 2 different
tables...how can I put them together so they are one...?

Thanks,
Matt

Nigel Armstrong <Nigel Ar*******@discussions.microsoft.com> wrote in message news:<70**********************************@microso ft.com>...
Hi Magister

Try creating a DataSet in Visual Studio .NET using the design time
environment - you will see that if you create an element, then add a couple
of 'fields' to it, then the structure you get in the xsd looks a bit like
this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Test" targetNamespace="http://tempuri.org/Test.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/Test.xsd"
xmlns:mstns="http://tempuri.org/Test.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Test" msdata:IsDataSet="true">
<xs:complexType>
<xs:all>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="Question" type="xs:string" minOccurs="0" />
<xs:element name="Answer" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

Then you can bind to the Question and Answer 'columns' by setting the
DataSource. Essentially the XML data needs to look more table like to work
the way that you want, with a root element representing the table, top level
element children of the root representing rows, and grand children of the
root representing columns.

HTH

Nigel

"magister" wrote:
Hello,

I have xml like this....

<test>
<question>sdfsa</question>
<section><question>43ga</question>
<question>asdf</question>
</test>

I make and xsd file with
<xs:all>
<xs:element....
<xs:element....
</xs:all>

I then bind the XML to a DataGrid...

DataGrid.DataSource = DataSet;
DataGrid.DataBind();

but I only get the questions, I notice there is a DataMember property
I can set to DataGrid.DataMember = "Section"; and I will get that one,
but essential I want a table with both elements in there...

Is there anyway to do this...?

Thank You

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
1
by: Torre Quinn | last post by:
Does anyone have any good sites or resources dealing with adding drag and drop functionality to a set of controls on a form? I'd like to try to get several examples of varied applications of drag...
2
by: Carolyn Vo | last post by:
I have been looking and looking but can't seem to find out how to get the row selected in a web control datagrid (NOT a web form datagrid!!!), and how to highlight the selected row. I'm sure this...
1
by: Michael Gorbach | last post by:
Iv got a StatisticsContainer object that contains an arraylist of objects of different types, all inherited from class Statistic. The statistics class has 2 string public properties, name and...
3
by: Raghuvansh | last post by:
I am databinding a grid to an XML source (given below). I am displaying the grid contents inside an TemplateColumn/ItemTemplate using regular <%# DataBinder.Eval(Container.DataItem,...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
5
by: lanem | last post by:
I want to display some drill-down data with a datagrid look. I can get the exact functionality I want with a treeview, but I don't like the way the treeview looks and formats the data. I want a...
3
by: Rodi Roberto | last post by:
Hi all, i have a problem on a datagrid (webforms), i don't know if is a problem on my code, if is a bug of DataGrid or simply if is normal... When i add a node on a datagrid or when i delete a...
2
by: Blacky | last post by:
Hi, I am using c# asp.net application.I have datagrid which binds column dynamically and i make certain columns say visibility to false in my itemdatabound event EMPID AS E.ITEM.CELLS.VISIBLE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.