473,547 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hierarchical data and Gridview

I'm trying to find a way to bind hierarchical data to a gridview control.
I've been able to do this with some third party controls and was wondering if
this functionality is available with the gridview control. Does anyone have a
guidance on this? Thanks
--
Live long, stay strong
Mar 13 '06 #1
4 7591
You can use the XPath data binding expression within ItemTemplates. For
example, if you had an xml that looks like this:
<RootNode>
<Node>
<Category ID="1">
<Product ID="1" Name="Product 1">
<Supplier ID="1">Descript ion for Supplier 1</Supplier>
<Supplier ID="2">Descript ion for Supplier 2</Supplier>
</Product>
</Category>

</Node>
</RootNode>

and an XMLDataSource object that reads that xml like this:

<asp:XmlDataSou rce ID="XmlDataSour ceControl1"
DataFile="~/App_Data/Products.xml"
XPath="RootNode/Node/Category[@ID='1']/Product" runat="Server" />

Then you can write a GridView with templates like this:

<asp:GridView ID="GridView1" runat="server" DataSourceID="X mlDataSource1"
AutoGenerateCol umns="false">
<Columns>
<asp:TemplateFi eld>
<HeaderTemplate >
Product ID</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%#XPath( "@ID")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<HeaderTemplate >
Product Name</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%#XPath( "Name")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<HeaderTemplate >
Product Name</HeaderTemplate>
<ItemTemplate >
<asp:DataList id="SupplierDat aList" DataSource='<%#
XPathSelect("Su pplier") %>' runat="server">
<ItemTemplate >
<br>
<u>
Supplier ID <%# XPath("@ID") %>:
<%# XPath("@ID") %>
</u>
<br>
<%# XPath(".") %>
</ItemTemplate>
</asp:DataList>

</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Congero" wrote:
I'm trying to find a way to bind hierarchical data to a gridview control.
I've been able to do this with some third party controls and was wondering if
this functionality is available with the gridview control. Does anyone have a
guidance on this? Thanks
--
Live long, stay strong

Mar 13 '06 #2
Hi Phillips, If my source of data is a table of Access or SQL from Access
for example

SELECT Group.Name, Product.Name,Pr oduct.Price FROM Gruop,Product where
Group.Code=Prod uct.Code

How I could make in GridView Hierarchical

Group1
Product1 12.00
Product2 13.56
Product3 16.35
Thanks.
Don Quijote de Nicaragua.
Elder Soto.

"Phillip Williams" <WE******@newsg roups.nospam> escribió en el mensaje
news:D9******** *************** ***********@mic rosoft.com...
You can use the XPath data binding expression within ItemTemplates. For
example, if you had an xml that looks like this:
<RootNode>
<Node>
<Category ID="1">
<Product ID="1" Name="Product 1">
<Supplier ID="1">Descript ion for Supplier 1</Supplier>
<Supplier ID="2">Descript ion for Supplier 2</Supplier>
</Product>
</Category>

</Node>
</RootNode>

and an XMLDataSource object that reads that xml like this:

<asp:XmlDataSou rce ID="XmlDataSour ceControl1"
DataFile="~/App_Data/Products.xml"
XPath="RootNode/Node/Category[@ID='1']/Product" runat="Server" />

Then you can write a GridView with templates like this:

<asp:GridView ID="GridView1" runat="server" DataSourceID="X mlDataSource1"
AutoGenerateCol umns="false">
<Columns>
<asp:TemplateFi eld>
<HeaderTemplate >
Product ID</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%#XPath( "@ID")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<HeaderTemplate >
Product Name</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="Label2" runat="server"
Text='<%#XPath( "Name")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<HeaderTemplate >
Product Name</HeaderTemplate>
<ItemTemplate >
<asp:DataList id="SupplierDat aList" DataSource='<%#
XPathSelect("Su pplier") %>' runat="server">
<ItemTemplate >
<br>
<u>
Supplier ID <%# XPath("@ID") %>:
<%# XPath("@ID") %>
</u>
<br>
<%# XPath(".") %>
</ItemTemplate>
</asp:DataList>

</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Congero" wrote:
I'm trying to find a way to bind hierarchical data to a gridview control.
I've been able to do this with some third party controls and was
wondering if
this functionality is available with the gridview control. Does anyone
have a
guidance on this? Thanks
--
Live long, stay strong

Mar 13 '06 #3
If you are looking to represent a one-level hierarchy from a relational
datatable you might create 2 dataviews for the same table by querying again
the same table during the GridView.RowDat aBound event handling to get a view
of the child records. I did a while ago a similar sample using the
DataGrid's ItemDataBound event. You might find it helpful in understanding
the concept and then you can create a similar implementation for the GridView:
http://www.societopia.net/Samples/Da...Hierarchy.aspx

If your hierarchy can be more than one level then you would need to use
recursion like I did using the datagrid in this sample:
http://www.societopia.net/samples/webform2.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Don Quijote de Nicaragua" wrote:
Hi Phillips, If my source of data is a table of Access or SQL from Access
for example

SELECT Group.Name, Product.Name,Pr oduct.Price FROM Gruop,Product where
Group.Code=Prod uct.Code

How I could make in GridView Hierarchical

Group1
Product1 12.00
Product2 13.56
Product3 16.35
Thanks.
Don Quijote de Nicaragua.
Elder Soto.

"Phillip Williams" <WE******@newsg roups.nospam> escribió en el mensaje
news:D9******** *************** ***********@mic rosoft.com...
You can use the XPath data binding expression within ItemTemplates. For
example, if you had an xml that looks like this:
<RootNode>
<Node>
<Category ID="1">
<Product ID="1" Name="Product 1">
<Supplier ID="1">Descript ion for Supplier 1</Supplier>
<Supplier ID="2">Descript ion for Supplier 2</Supplier>
</Product>
</Category>

</Node>
</RootNode>

and an XMLDataSource object that reads that xml like this:

<asp:XmlDataSou rce ID="XmlDataSour ceControl1"
DataFile="~/App_Data/Products.xml"
XPath="RootNode/Node/Category[@ID='1']/Product" runat="Server" />

Then you can write a GridView with templates like this:

<asp:GridView ID="GridView1" runat="server" DataSourceID="X mlDataSource1"
AutoGenerateCol umns="false">
<Columns>
<asp:TemplateFi eld>
<HeaderTemplate >
Product ID</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%#XPath( "@ID")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<HeaderTemplate >
Product Name</HeaderTemplate>
<ItemTemplate >
<asp:Label ID="Label2" runat="server"
Text='<%#XPath( "Name")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<HeaderTemplate >
Product Name</HeaderTemplate>
<ItemTemplate >
<asp:DataList id="SupplierDat aList" DataSource='<%#
XPathSelect("Su pplier") %>' runat="server">
<ItemTemplate >
<br>
<u>
Supplier ID <%# XPath("@ID") %>:
<%# XPath("@ID") %>
</u>
<br>
<%# XPath(".") %>
</ItemTemplate>
</asp:DataList>

</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Congero" wrote:
I'm trying to find a way to bind hierarchical data to a gridview control.
I've been able to do this with some third party controls and was
wondering if
this functionality is available with the gridview control. Does anyone
have a
guidance on this? Thanks
--
Live long, stay strong


Mar 14 '06 #4
Thank you very much, I am going to study it
Don Quijote de Nicaragua.
Elder Soto.
"Phillip Williams" <WE******@newsg roups.nospam> escribió en el mensaje
news:4A******** *************** ***********@mic rosoft.com...
If you are looking to represent a one-level hierarchy from a relational
datatable you might create 2 dataviews for the same table by querying
again
the same table during the GridView.RowDat aBound event handling to get a
view
of the child records. I did a while ago a similar sample using the
DataGrid's ItemDataBound event. You might find it helpful in
understanding
the concept and then you can create a similar implementation for the
GridView:
http://www.societopia.net/Samples/Da...Hierarchy.aspx

If your hierarchy can be more than one level then you would need to use
recursion like I did using the datagrid in this sample:
http://www.societopia.net/samples/webform2.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Don Quijote de Nicaragua" wrote:
Hi Phillips, If my source of data is a table of Access or SQL from Access
for example

SELECT Group.Name, Product.Name,Pr oduct.Price FROM Gruop,Product where
Group.Code=Prod uct.Code

How I could make in GridView Hierarchical

Group1
Product1 12.00
Product2 13.56
Product3 16.35
Thanks.
Don Quijote de Nicaragua.
Elder Soto.

"Phillip Williams" <WE******@newsg roups.nospam> escribió en el mensaje
news:D9******** *************** ***********@mic rosoft.com...
> You can use the XPath data binding expression within ItemTemplates. For
> example, if you had an xml that looks like this:
> <RootNode>
> <Node>
> <Category ID="1">
> <Product ID="1" Name="Product 1">
> <Supplier ID="1">Descript ion for Supplier 1</Supplier>
> <Supplier ID="2">Descript ion for Supplier 2</Supplier>
> </Product>
> </Category>
>
> </Node>
> </RootNode>
>
> and an XMLDataSource object that reads that xml like this:
>
> <asp:XmlDataSou rce ID="XmlDataSour ceControl1"
> DataFile="~/App_Data/Products.xml"
> XPath="RootNode/Node/Category[@ID='1']/Product" runat="Server" />
>
> Then you can write a GridView with templates like this:
>
> <asp:GridView ID="GridView1" runat="server"
> DataSourceID="X mlDataSource1"
> AutoGenerateCol umns="false">
> <Columns>
> <asp:TemplateFi eld>
> <HeaderTemplate >
> Product ID</HeaderTemplate>
> <ItemTemplate >
> <asp:Label ID="Label1" runat="server"
> Text='<%#XPath( "@ID")
> %>'></asp:Label>
> </ItemTemplate>
> </asp:TemplateFie ld>
> <asp:TemplateFi eld>
> <HeaderTemplate >
> Product Name</HeaderTemplate>
> <ItemTemplate >
> <asp:Label ID="Label2" runat="server"
> Text='<%#XPath( "Name")
> %>'></asp:Label>
> </ItemTemplate>
> </asp:TemplateFie ld>
> <asp:TemplateFi eld>
> <HeaderTemplate >
> Product Name</HeaderTemplate>
> <ItemTemplate >
> <asp:DataList id="SupplierDat aList" DataSource='<%#
> XPathSelect("Su pplier") %>' runat="server">
> <ItemTemplate >
> <br>
> <u>
> Supplier ID <%# XPath("@ID") %>:
> <%# XPath("@ID") %>
> </u>
> <br>
> <%# XPath(".") %>
> </ItemTemplate>
> </asp:DataList>
>
> </ItemTemplate>
> </asp:TemplateFie ld>
> </Columns>
> </asp:GridView>
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Congero" wrote:
>
>> I'm trying to find a way to bind hierarchical data to a gridview
>> control.
>> I've been able to do this with some third party controls and was
>> wondering if
>> this functionality is available with the gridview control. Does anyone
>> have a
>> guidance on this? Thanks
>> --
>> Live long, stay strong


Mar 14 '06 #5

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

Similar topics

4
2595
by: Daisy | last post by:
Let's say I've got a forum, where users can be moderators of each forum. Tables look like this: USER -------- user_key name FORUM
5
2238
by: clintonG | last post by:
I'm looking for documentation and would not turn my nose up to any code from anybody who thinks they are good at the design of an algorythm that can be used to generated a hierarchical relational data model. What? A Yahoo-like drill-down menu that is a series of categories and nested categories is a hierarchical relational data model. An...
0
1429
by: stigbn | last post by:
When a DataSet is used as data source for a DataGrid one can get hiearachical datagrid by using relations among the DataTables of the DataSet. (By hierarchical datagrid, I mean columns that can be expanded and collapsed with '+' buttons). How can I achieve a hierarchical DataGrid when using an ArrayList as data source? I have tried...
0
1193
by: Don Quijote de Nicaragua | last post by:
Hi, How I can createg a GridView Hierarchical using a GridView that comes in VS.2005 Thanks. Don Quijote de Nicaragua
7
14789
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1...
1
5622
by: mgonzales3 | last post by:
What is best method to create a nested gridview? Thanks
1
1522
by: boomhauer | last post by:
I cant seem to find info online about this so thought id ask.. I have an asp.net 2.0 page that has: 1. an infragistics calendar control 2. a DDL that has an ODS with a param pulled from the calendar 3. a gridview with ODS that binds a param from the DDL key the problem im having is, on chanigng the infragistics calendar, the page seems...
2
4661
by: Chris | last post by:
I keep my data in an array and using TextMatrix property for filling the control cells. I am not using recordset. Is there any way for creating bands programmatically in a Hierarchical GridView Control for expanding and collapsing rows ? Thanks a lot in advance.
6
8890
by: Guabble | last post by:
Hi Can anyone help me? I want to be able to show my sqldatareader contents in a gridview whereby the child data is concatenated up in a single row. Is this possible? For example Author Name Book Titles Author1 Book1, Book2, Book3
0
7510
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...
0
7437
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...
0
7703
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. ...
1
7463
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...
0
6032
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...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3493
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...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.