473,401 Members | 2,125 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,401 software developers and data experts.

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 7579
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">Description for Supplier 1</Supplier>
<Supplier ID="2">Description for Supplier 2</Supplier>
</Product>
</Category>

</Node>
</RootNode>

and an XMLDataSource object that reads that xml like this:

<asp:XmlDataSource ID="XmlDataSourceControl1"
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="XmlDataSource1"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Product ID</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#XPath("@ID")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#XPath("Name")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp:DataList id="SupplierDataList" DataSource='<%#
XPathSelect("Supplier") %>' runat="server">
<ItemTemplate>
<br>
<u>
Supplier ID <%# XPath("@ID") %>:
<%# XPath("@ID") %>
</u>
<br>
<%# XPath(".") %>
</ItemTemplate>
</asp:DataList>

</ItemTemplate>
</asp:TemplateField>
</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,Product.Price FROM Gruop,Product where
Group.Code=Product.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******@newsgroups.nospam> escribió en el mensaje
news:D9**********************************@microsof t.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">Description for Supplier 1</Supplier>
<Supplier ID="2">Description for Supplier 2</Supplier>
</Product>
</Category>

</Node>
</RootNode>

and an XMLDataSource object that reads that xml like this:

<asp:XmlDataSource ID="XmlDataSourceControl1"
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="XmlDataSource1"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Product ID</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#XPath("@ID")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%#XPath("Name")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp:DataList id="SupplierDataList" DataSource='<%#
XPathSelect("Supplier") %>' runat="server">
<ItemTemplate>
<br>
<u>
Supplier ID <%# XPath("@ID") %>:
<%# XPath("@ID") %>
</u>
<br>
<%# XPath(".") %>
</ItemTemplate>
</asp:DataList>

</ItemTemplate>
</asp:TemplateField>
</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.RowDataBound 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,Product.Price FROM Gruop,Product where
Group.Code=Product.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******@newsgroups.nospam> escribió en el mensaje
news:D9**********************************@microsof t.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">Description for Supplier 1</Supplier>
<Supplier ID="2">Description for Supplier 2</Supplier>
</Product>
</Category>

</Node>
</RootNode>

and an XMLDataSource object that reads that xml like this:

<asp:XmlDataSource ID="XmlDataSourceControl1"
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="XmlDataSource1"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Product ID</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#XPath("@ID")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%#XPath("Name")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp:DataList id="SupplierDataList" DataSource='<%#
XPathSelect("Supplier") %>' runat="server">
<ItemTemplate>
<br>
<u>
Supplier ID <%# XPath("@ID") %>:
<%# XPath("@ID") %>
</u>
<br>
<%# XPath(".") %>
</ItemTemplate>
</asp:DataList>

</ItemTemplate>
</asp:TemplateField>
</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******@newsgroups.nospam> escribió en el mensaje
news:4A**********************************@microsof t.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.RowDataBound 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,Product.Price FROM Gruop,Product where
Group.Code=Product.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******@newsgroups.nospam> escribió en el mensaje
news:D9**********************************@microsof t.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">Description for Supplier 1</Supplier>
> <Supplier ID="2">Description for Supplier 2</Supplier>
> </Product>
> </Category>
>
> </Node>
> </RootNode>
>
> and an XMLDataSource object that reads that xml like this:
>
> <asp:XmlDataSource ID="XmlDataSourceControl1"
> 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="XmlDataSource1"
> AutoGenerateColumns="false">
> <Columns>
> <asp:TemplateField>
> <HeaderTemplate>
> Product ID</HeaderTemplate>
> <ItemTemplate>
> <asp:Label ID="Label1" runat="server"
> Text='<%#XPath("@ID")
> %>'></asp:Label>
> </ItemTemplate>
> </asp:TemplateField>
> <asp:TemplateField>
> <HeaderTemplate>
> Product Name</HeaderTemplate>
> <ItemTemplate>
> <asp:Label ID="Label2" runat="server"
> Text='<%#XPath("Name")
> %>'></asp:Label>
> </ItemTemplate>
> </asp:TemplateField>
> <asp:TemplateField>
> <HeaderTemplate>
> Product Name</HeaderTemplate>
> <ItemTemplate>
> <asp:DataList id="SupplierDataList" DataSource='<%#
> XPathSelect("Supplier") %>' runat="server">
> <ItemTemplate>
> <br>
> <u>
> Supplier ID <%# XPath("@ID") %>:
> <%# XPath("@ID") %>
> </u>
> <br>
> <%# XPath(".") %>
> </ItemTemplate>
> </asp:DataList>
>
> </ItemTemplate>
> </asp:TemplateField>
> </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
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
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...
0
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...
0
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
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...
1
by: mgonzales3 | last post by:
What is best method to create a nested gridview? Thanks
1
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...
2
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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
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...
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
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...

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.