473,236 Members | 1,628 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,236 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 3231
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.