Sorted DataView, but unsorted datalist when bound to the dataview

Discussion in 'ASP .Net' started by CodeMonkey, Jul 20, 2007.

  1. CodeMonkey

    CodeMonkey Guest

    Hi all
    I create a dataset from an xml file with schema and from the dataset a
    sorted dataview. I have tested the contents of the dataview and it is
    correctly sorted. However when I bind the dataview to a datalist
    control, the rows seem to be swapped. All the data is in the datalist
    and changing the sortkeys around does have an effect but I cannot
    understand why the order is messed up like this.

    Any help is really appreciated.

    Andrew

    My XML File is further on below. Sorted data in the dataview appears
    like this:

    STUFF1
    STUFF2
    STUFF3
    STUFF4
    STUFF5
    STUFF6

    but the datalist control on the web page shows it like this:

    STUFF1
    STUFF4
    STUFF2
    STUFF5
    STUFF3
    STUFF6


    Here is my code:

    Dim abcSwdbNews As DataSet
    abcSwdbNews = New DataSet
    abcSwdbNews.ReadXml(ConfigurationManager.AppSettings("SwDbNews"),
    XmlReadMode.ReadSchema)
    'Sort the Dataset - first table - on datbase name
    Dim DV As DataView

    DV = abcSwdbNews.Tables(0).DefaultView
    Dim Value As Type
    Value = abcSwdbNews.Tables(0).Columns(0).DataType
    'Value correctly returns int32

    DV.Sort = "sortkey ASC"

    'Set the datasource to the default view
    DataList3.DataSource = DV

    DataList3.DataBind()


    Here is the relavent markup:

    <asp:DataList ID="DataList3" runat="server" BackColor="#CCCCCC"
    BorderColor="#999999"
    BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
    ForeColor="Black"
    GridLines="Both" Style="position: relative" RepeatColumns="2" >
    <FooterStyle BackColor="#CCCCCC" />
    <SelectedItemStyle BackColor="#000099" Font-Bold="True"
    ForeColor="White" />
    <ItemStyle BackColor="White" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <HeaderTemplate>
    Recent Changes
    </HeaderTemplate>
    <FooterTemplate>

    </FooterTemplate>
    <ItemTemplate>
    <tr>
    <td><%#Container.DataItem("db")%></td>
    <td><%#Container.DataItem("Feature")%></td>
    </tr>
    </ItemTemplate>
    </asp:DataList>

    Here is the XML file:

    <?xml version="1.0" standalone="yes"?>
    <Releases>
    <xs:schema id="Releases" xmlns="" xmlns:xs="http://www.w3.org/2001/
    XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="Releases" msdata:IsDataSet="true"
    msdata:Locale="en-US">
    <xs:complexType>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="Release">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="sortkey" type="xs:int"
    minOccurs="0" />
    <xs:element name="db" type="xs:string" minOccurs="0" /
    >

    <xs:element name="Feature" type="xs:string"
    minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="Databases">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="swdb" type="xs:string"
    minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    <Release>
    <sortkey>1</sortkey>
    <db>STUFF1</db>
    <Feature>Some Great Stuff1</Feature>
    </Release>
    <Release>
    <sortkey>2</sortkey>
    <db>STUFF2</db>
    <Feature>Some Great Stuff2</Feature>
    </Release>
    <Release>
    <sortkey>3</sortkey>
    <db>STUFF3</db>
    <Feature>Some Great Stuff3</Feature>
    </Release>
    <Release>
    <sortkey>4</sortkey>
    <db>STUFF4</db>
    <Feature>Some Great Stuff4</Feature>
    </Release>
    <Release>
    <sortkey>5</sortkey>
    <db>STUFF5</db>
    <Feature>Some Great Stuff5</Feature>
    </Release>
    <Release>
    <sortkey>6</sortkey>
    <db>STUFF6</db>
    <Feature>Some Great Stuff6</Feature>
    </Release>
    <Databases>
    <swdb>abcSWdb3Q07-02.mde</swdb>
    </Databases>
    </Releases>
     
    CodeMonkey, Jul 20, 2007
    #1
    1. Advertising

  2. In the html/inline page, In the datalist property you don't need to use RepeatColumns.

    Remove the RepeatColumn from the definition of datalist and try after that.

    Thanks.

    -J
    Joyal Jhaveri

    > On Friday, July 20, 2007 11:18 AM CodeMonkey wrote:


    > Hi all
    > I create a dataset from an xml file with schema and from the dataset a
    > sorted dataview. I have tested the contents of the dataview and it is
    > correctly sorted. However when I bind the dataview to a datalist
    > control, the rows seem to be swapped. All the data is in the datalist
    > and changing the sortkeys around does have an effect but I cannot
    > understand why the order is messed up like this.
    >
    > Any help is really appreciated.
    >
    > Andrew
    >
    > My XML File is further on below. Sorted data in the dataview appears
    > like this:
    >
    > STUFF1
    > STUFF2
    > STUFF3
    > STUFF4
    > STUFF5
    > STUFF6
    >
    > but the datalist control on the web page shows it like this:
    >
    > STUFF1
    > STUFF4
    > STUFF2
    > STUFF5
    > STUFF3
    > STUFF6
    >
    >
    > Here is my code:
    >
    > Dim abcSwdbNews As DataSet
    > abcSwdbNews = New DataSet
    > abcSwdbNews.ReadXml(ConfigurationManager.AppSettings("SwDbNews"),
    > XmlReadMode.ReadSchema)
    > 'Sort the Dataset - first table - on datbase name
    > Dim DV As DataView
    >
    > DV = abcSwdbNews.Tables(0).DefaultView
    > Dim Value As Type
    > Value = abcSwdbNews.Tables(0).Columns(0).DataType
    > 'Value correctly returns int32
    >
    > DV.Sort = "sortkey ASC"
    >
    > 'Set the datasource to the default view
    > DataList3.DataSource = DV
    >
    > DataList3.DataBind()
    >
    >
    > Here is the relavent markup:
    >
    > <asp:DataList ID="DataList3" runat="server" BackColor="#CCCCCC"
    > BorderColor="#999999"
    > BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
    > ForeColor="Black"
    > GridLines="Both" Style="position: relative" RepeatColumns="2" >
    > <FooterStyle BackColor="#CCCCCC" />
    > <SelectedItemStyle BackColor="#000099" Font-Bold="True"
    > ForeColor="White" />
    > <ItemStyle BackColor="White" />
    > <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    > <HeaderTemplate>
    > Recent Changes
    > </HeaderTemplate>
    > <FooterTemplate>
    >
    > </FooterTemplate>
    > <ItemTemplate>
    > <tr>
    > <td><%#Container.DataItem("db")%></td>
    > <td><%#Container.DataItem("Feature")%></td>
    > </tr>
    > </ItemTemplate>
    > </asp:DataList>
    >
    > Here is the XML file:
    >
    > <?xml version="1.0" standalone="yes"?>
    > <Releases>
    > <xs:schema id="Releases" xmlns="" xmlns:xs="http://www.w3.org/2001/
    > XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    > <xs:element name="Releases" msdata:IsDataSet="true"
    > msdata:Locale="en-US">
    > <xs:complexType>
    > <xs:choice minOccurs="0" maxOccurs="unbounded">
    > <xs:element name="Release">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="sortkey" type="xs:int"
    > minOccurs="0" />
    > <xs:element name="db" type="xs:string" minOccurs="0" /
    > <xs:element name="Feature" type="xs:string"
    > minOccurs="0" />
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    > <xs:element name="Databases">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="swdb" type="xs:string"
    > minOccurs="0" />
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    > </xs:choice>
    > </xs:complexType>
    > </xs:element>
    > </xs:schema>
    > <Release>
    > <sortkey>1</sortkey>
    > <db>STUFF1</db>
    > <Feature>Some Great Stuff1</Feature>
    > </Release>
    > <Release>
    > <sortkey>2</sortkey>
    > <db>STUFF2</db>
    > <Feature>Some Great Stuff2</Feature>
    > </Release>
    > <Release>
    > <sortkey>3</sortkey>
    > <db>STUFF3</db>
    > <Feature>Some Great Stuff3</Feature>
    > </Release>
    > <Release>
    > <sortkey>4</sortkey>
    > <db>STUFF4</db>
    > <Feature>Some Great Stuff4</Feature>
    > </Release>
    > <Release>
    > <sortkey>5</sortkey>
    > <db>STUFF5</db>
    > <Feature>Some Great Stuff5</Feature>
    > </Release>
    > <Release>
    > <sortkey>6</sortkey>
    > <db>STUFF6</db>
    > <Feature>Some Great Stuff6</Feature>
    > </Release>
    > <Databases>
    > <swdb>abcSWdb3Q07-02.mde</swdb>
    > </Databases>
    > </Releases>



    > Submitted via EggHeadCafe
    > ASP.NET Drawing a chart using OWC11 - Office Web Components
    > http://www.eggheadcafe.com/tutorial...chart-using-owc11--office-web-components.aspx
     
    joyal jhaveri, Feb 4, 2011
    #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. Nathan Baulch
    Replies:
    0
    Views:
    1,945
    Nathan Baulch
    Jun 26, 2003
  2. Gyruss
    Replies:
    1
    Views:
    4,108
    John C. Bollinger
    Apr 11, 2005
  3. =?Utf-8?B?QVNQIERldmVsb3Blcg==?=

    How do you bind a datalist that is inside a bound datalist

    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Sep 25, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    597
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=
    Sep 26, 2006
  4. JimLad
    Replies:
    0
    Views:
    396
    JimLad
    Jul 16, 2010
  5. GoodMorningSky

    How to sort datagrid and keep the bound data as sorted?

    GoodMorningSky, Sep 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    169
    GoodMorningSky
    Sep 9, 2004
Loading...

Share This Page