Sorting XML data in a DataGrid

Discussion in 'ASP .Net' started by slinky, Jul 11, 2007.

  1. slinky

    slinky Guest

    I have an XML file that is successfully displaying in my datagrid on
    my .aspx. I need to sort the data before it displays:

    Here's my .aspx code:


    <%@ import Namespace="System.Data" %>
    <script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim myDataSet As New DataSet()
    dgBooksPretty.DataSource = myDataSet
    dgBooksPretty.AllowSorting = True
    myDataSet.ReadXml(Server.MapPath("JFKtimeline.xml"))
    dgBooksPretty.DataBind()
    End Sub
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
    <title>President John Fitzgerald Kennedy Biographical Timetable</
    title>
    </head>
    <body borderwidth="20px">


    <asp:datagrid id="dgBooks"
    runat="server"
    Visible="False"
    Height="1px"
    Width="1px" />
    <asp:datagrid id="dgBooksPretty"
    runat="server"
    AutoGenerateColumns="False"
    Font-Name="Verdana"
    Font-Size="Small"
    HorizontalAlign="Center"
    ItemStyle-BackColor="#C0FFC0"
    AlternatingItemStyle-BackColor="White"
    Width="911px"
    Height="128px"
    AllowSorting="True"
    BorderColor="PeachPuff"
    BorderStyle="Outset"
    BorderWidth="10px">
    <HeaderStyle BackColor="DarkGreen"
    HorizontalAlign="Center"
    ForeColor="White"
    Font-Bold="True" />
    <Columns>
    <asp:BoundColumn HeaderText="Event" DataField="event" />
    <asp:BoundColumn HeaderText="Year" DataField="year" />
    </Columns>
    <AlternatingItemStyle BackColor="White" />
    <ItemStyle BackColor="#C0FFC0" />
    </asp:datagrid>
    <p align="center">
    </p>
    </body>
    </html>


    And here is an XSL file for the sorting, but I can't seem to find any
    logic to get the sort done... any ideas? Thanks!!!


    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:eek:utput method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:template match="events">
    <xsl:copy>
    <xsl:apply-templates select="topic">
    <xsl:sort select="year" data-type="number"/>
    </xsl:apply-templates>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="@* | node()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>
    slinky, Jul 11, 2007
    #1
    1. Advertising

  2. On Jul 11, 4:49 pm, slinky <> wrote:
    > I have an XML file that is successfully displaying in my datagrid on
    > my .aspx. I need to sort the data before it displays:
    >
    > Here's my .aspx code:
    >
    > <%@ import Namespace="System.Data" %>
    > <script runat="server">
    > Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    > Dim myDataSet As New DataSet()
    > dgBooksPretty.DataSource = myDataSet
    > dgBooksPretty.AllowSorting = True
    > myDataSet.ReadXml(Server.MapPath("JFKtimeline.xml"))
    > dgBooksPretty.DataBind()
    > End Sub
    > </script>
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head id="Head1" runat="server">
    > <title>President John Fitzgerald Kennedy Biographical Timetable</
    > title>
    > </head>
    > <body borderwidth="20px">
    >
    > <asp:datagrid id="dgBooks"
    > runat="server"
    > Visible="False"
    > Height="1px"
    > Width="1px" />
    > <asp:datagrid id="dgBooksPretty"
    > runat="server"
    > AutoGenerateColumns="False"
    > Font-Name="Verdana"
    > Font-Size="Small"
    > HorizontalAlign="Center"
    > ItemStyle-BackColor="#C0FFC0"
    > AlternatingItemStyle-BackColor="White"
    > Width="911px"
    > Height="128px"
    > AllowSorting="True"
    > BorderColor="PeachPuff"
    > BorderStyle="Outset"
    > BorderWidth="10px">
    > <HeaderStyle BackColor="DarkGreen"
    > HorizontalAlign="Center"
    > ForeColor="White"
    > Font-Bold="True" />
    > <Columns>
    > <asp:BoundColumn HeaderText="Event" DataField="event" />
    > <asp:BoundColumn HeaderText="Year" DataField="year" />
    > </Columns>
    > <AlternatingItemStyle BackColor="White" />
    > <ItemStyle BackColor="#C0FFC0" />
    > </asp:datagrid>
    > <p align="center">
    > </p>
    > </body>
    > </html>
    >
    > And here is an XSL file for the sorting, but I can't seem to find any
    > logic to get the sort done... any ideas? Thanks!!!
    >
    > <xsl:stylesheet
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    > <xsl:strip-space elements="*"/>
    > <xsl:eek:utput method="xml" indent="yes" encoding="UTF-8"/>
    > <xsl:template match="events">
    > <xsl:copy>
    > <xsl:apply-templates select="topic">
    > <xsl:sort select="year" data-type="number"/>
    > </xsl:apply-templates>
    > </xsl:copy>
    > </xsl:template>
    > <xsl:template match="@* | node()">
    > <xsl:copy>
    > <xsl:apply-templates select="@* | node()"/>
    > </xsl:copy>
    > </xsl:template>
    > </xsl:stylesheet>


    http://groups.google.com/group/micr....aspnet/browse_thread/thread/f1e4d2860f00fa02
    Alexey Smirnov, Jul 11, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,401
    James Kanze
    Jul 6, 2010
  2. Don

    Sorting a Datagrid that gets data from an XML file

    Don, Aug 25, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    113
  3. AlainCD
    Replies:
    0
    Views:
    196
    AlainCD
    Jan 12, 2006
  4. Jason
    Replies:
    0
    Views:
    370
    Jason
    Oct 4, 2006
  5. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    463
    Michael Budash
    Oct 11, 2003
Loading...

Share This Page