473,396 Members | 1,785 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,396 software developers and data experts.

XML newbee ask for some help trying to build a nested datagrid

i'm developing a faq session of our website and I'm facing some
problems handling xml files and DataSet relations

First off all, here's the structure of my xml file:

<?xml version="1.0"?>
<questions>
<topic order="1" title="General">
<item order="1" question="blablabla?">
<answer>blablabla</answer>
</item>
<item order="2" question="blablabla?">
<answer>blablabla</answer>
</item>
</topic>
<topic order="2" title="Police Office">
<item order="1" question="blablabla?">
<answer>blablabla</answer>
</item>
</topic>
<topic order="2" title="Ensurance">
<item order="1" question="blablabla?">
<answer>blablabla</answer>
</item>
<item order="2" question="blablabla?">
<answer>blablabla</answer>
</item>
<item order="3" question="blablabla?">
<answer>blablabla</answer>
</item>
</topic>

and so on...This structure is acceptable? I'm forgetting something? I
know it doesnt have an schema, but I havent learned how to build one
yet.

Now the code

I have two datagrids, as the MS sample (in
http://support.microsoft.com/default...b;en-us;308485)
but I have changed something to simplify

private void Page_Load(object sender, System.EventArgs e)
{ // Put user code to initialize the page here
string filename = Server.MapPath(".");
XmlDocument doc = new XmlDocument();
doc.Load(filename + "\\perguntas.xml");

// this function reads the xml file and create 3 tables (topics, itens
and answers) whithin a dataset ds
ds = ReadXml(doc);
ds.Relations.Add("rel", ds.Tables["topics"].Columns["order"],
ds.Tables["itens"].Columns["order"]);
grid1.DataSource = ds;
grid1.DataMember = "topics";
grid1.DataKeyField = "order";
grid1.DataBind(); }

up to here, everything is ok, I can load the xml file and show the
first level of it (the <topic) tag's colection with a '+' at the left
side where I want the child elements (in this case the <itens> tags)

Now the problem. When I click in the '+' column the event
OnSelectedIndexChanged is fired.

//delegate for OnSelectedIndexChanged of Grid1
protected void grid1_OnSelectedIndexChanged(System.Object sender,
System.EventArgs e) {
this.Showdetailgrid(); }

Following, the function that handles the event (where the error come
out)

// handle the event
protected void Showdetailgrid() {
if(grid1.SelectedIndex != -1)
{
DataView parentrows = new DataView();
DataView childrows;
DataRowView currentparentrow;
parentrows.Table = ds.Tables["itens"];
currentparentrow = parentrows[grid1.SelectedIndex];
childrows = currentparentrow.CreateChildView("rel"); ***

grid2.DataSource = childrows;
grid2.DataBind();
grid2.Visible = true;
}
else
grid2.Visible = false;
}

When the line with *** is executed I got the following error:

System.ArgumentException: The relation is not parented to the table to
which this DataView points.

Could someone help me please?
Nov 15 '05 #1
0 1378

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

Similar topics

0
by: NETDeveloper | last post by:
Hi, I almost have my nested datagrid working properly. I created a datagrid on a user control and dropped that onto another datagrid. At first, I noticed when I was stepping through the code,...
1
by: Dave | last post by:
I have a datagrid with another datagrid in a template column. For the second datagrids datasource I use container.dataitem.createchildview("relationship") I want to discover if the nested...
0
by: Chad Folden | last post by:
I can't figure out how to use the EditCommand for the nested datagrid .. HELP PLEASE ;-) It works perfectly for the parent datagrid, but will not display, even though the EditCommand event is...
2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
2
by: Matthew | last post by:
I have a DataGrid nested within a DataList. The DataGrid generates LinkButtons with specific CommandName values. I cannot figure out how to trap this event. I need to know which DataGrid...
0
by: Linus | last post by:
Hi, I have a datagrid nested inside another datagrid, the edit/update/cancel command works fine on the outter datagrid but I'm having problems with the inner one. There are 2 problems and here's...
0
by: Pat | last post by:
I have 3 Datagrid nested. Master Details Child The master has paging (And i'm using the paging inbuilt in the Datagrid) in the Master DataGrid you select a linkbutton(using commandname) and it...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
4
by: Bartc | last post by:
"vaib" <vaibhavpanghal@gmail.comwrote in message news:26a44cc5-0f08-41fe-859b-0d27daf3ca1d@f24g2000prh.googlegroups.com... I don't know the formal approach to these things but I haven't come...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.