Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Hierarchical data and Gridview (http://www.velocityreviews.com/forums/t121483-hierarchical-data-and-gridview.html)

=?Utf-8?B?Q29uZ2Vybw==?= 03-13-2006 05:30 PM

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

=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= 03-13-2006 06:01 PM

RE: Hierarchical data and Gridview
 
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


Don Quijote de Nicaragua 03-13-2006 07:48 PM

Re: Hierarchical data and Gridview
 
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" <WEBSWAPP@newsgroups.nospam> escribió en el mensaje
news:D9758B5A-359D-49AC-9357-1A6E6D6D0610@microsoft.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




=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= 03-14-2006 12:39 PM

Re: Hierarchical data and Gridview
 
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" <WEBSWAPP@newsgroups.nospam> escribió en el mensaje
> news:D9758B5A-359D-49AC-9357-1A6E6D6D0610@microsoft.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

>
>
>


Don Quijote de Nicaragua 03-14-2006 02:07 PM

Re: Hierarchical data and Gridview
 
Thank you very much, I am going to study it
Don Quijote de Nicaragua.
Elder Soto.


"Phillip Williams" <WEBSWAPP@newsgroups.nospam> escribió en el mensaje
news:4A8D2F92-21CB-480A-98D4-B4E27955197F@microsoft.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" <WEBSWAPP@newsgroups.nospam> escribió en el mensaje
>> news:D9758B5A-359D-49AC-9357-1A6E6D6D0610@microsoft.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

>>
>>
>>





All times are GMT. The time now is 11:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.