473,734 Members | 2,798 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 1410

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

Similar topics

0
1739
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
2671
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
2261
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
3301
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
1239
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
1344
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
2090
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
3255
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
8946
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
8776
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
9449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9182
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...
1
6735
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
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.