473,811 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="blabl abla?">
<answer>blablab la</answer>
</item>
<item order="2" question="blabl abla?">
<answer>blablab la</answer>
</item>
</topic>
<topic order="2" title="Police Office">
<item order="1" question="blabl abla?">
<answer>blablab la</answer>
</item>
</topic>
<topic order="2" title="Ensuranc e">
<item order="1" question="blabl abla?">
<answer>blablab la</answer>
</item>
<item order="2" question="blabl abla?">
<answer>blablab la</answer>
</item>
<item order="3" question="blabl abla?">
<answer>blablab la</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(objec t sender, System.EventArg s e)
{ // Put user code to initialize the page here
string filename = Server.MapPath( ".");
XmlDocument doc = new XmlDocument();
doc.Load(filena me + "\\perguntas.xm l");

// this function reads the xml file and create 3 tables (topics, itens
and answers) whithin a dataset ds
ds = ReadXml(doc);
ds.Relations.Ad d("rel", ds.Tables["topics"].Columns["order"],
ds.Tables["itens"].Columns["order"]);
grid1.DataSourc e = ds;
grid1.DataMembe r = "topics";
grid1.DataKeyFi eld = "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
OnSelectedIndex Changed is fired.

//delegate for OnSelectedIndex Changed of Grid1
protected void grid1_OnSelecte dIndexChanged(S ystem.Object sender,
System.EventArg s e) {
this.Showdetail grid(); }

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

// handle the event
protected void Showdetailgrid( ) {
if(grid1.Select edIndex != -1)
{
DataView parentrows = new DataView();
DataView childrows;
DataRowView currentparentro w;
parentrows.Tabl e = ds.Tables["itens"];
currentparentro w = parentrows[grid1.SelectedI ndex];
childrows = currentparentro w.CreateChildVi ew("rel"); ***

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

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

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

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

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

Similar topics

0
1744
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, that the update linkbutton actually goes to the edit command instead of the update command (which I'm pretty sure would be a bug). Anyway, I took out the editcommmand column and replaced it with a regular template column. Within the...
1
2677
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 datagrid has any rows. I think I need to check the datagrid.items.count on the second datagrid in the first datagrids ItemCreated event but I can't seem to figure out how to address the second datagrid. Does anyone have any ideas?
0
2262
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 firing for the child datagrid. I have set up a test page for myself to see if I can get this to work ..any help is appreciated! Thanks in advance (This is my complete page and code behind) <asp:DataGrid ID="_dgProj" AllowPaging=False
2
3304
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 reference not set to an instance of an object". This error message commonly occurs when a server control is incorrecly declared, so naturally I have double checked this. To test this, I moved the aspx code for the DataGrid ('myNestedDataGrid')...
2
3285
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 LinkButton was selected. Thanks in advance.
0
1242
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 the code for my inner datagrid's EditCommand: public void dgInner_EditCommand(object sender, DataGridCommandEventArgs e) {
0
1347
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 populates the data in the Details DataGrid (I'm using Dim Filter As String = CStr(dtgMaster.DataKeys(dtgMaster.SelectedIndex)).Replace("'", "''") to filter btw the Datagrids)
0
2094
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 help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
4
3267
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 across an RE grammar before, not for an entire language anyway. The usual approach if you're not using external tools is to program using 'recursive descent' or top-down, whatever the term is. In this case the grammar is built-in to the code. You...
0
9728
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10402
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10135
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.