Professional Web Applications Themes

DataGrid-DataView-XML-Sorting strings as numeric - ASP.NET Data Grid Control

I am populating a DataGrid with xml. I need to be able to sort some of the columns. However, the DataView.Sort is treating my strings (which are numbers in string form) as strings and not formatting them as numbers. So, I get: 1,11,2,22 instead of: 1,2,11,22 How do I get the DataView.Sort to treat these strings as a numeric type? Thanks....

  1. #1

    Default DataGrid-DataView-XML-Sorting strings as numeric

    I am populating a DataGrid with xml. I need to be able to
    sort some of the columns. However, the DataView.Sort is
    treating my strings (which are numbers in string form) as
    strings and not formatting them as numbers. So, I get:

    1,11,2,22

    instead of:

    1,2,11,22

    How do I get the DataView.Sort to treat these strings as a
    numeric type?

    Thanks.
    Joe Rattz Guest

  2. #2

    Default Re: DataGrid-DataView-XML-Sorting strings as numeric

    Here's a good way to do it...

    First... You need to create an XML schema file along with your xml file.

    Here's an example:

    XML File:

    <?xml version="1.0" encoding="utf-8" ?>
    <Projects xmlns="projects.xsd">
    <Project>
    <ID>1</ID>
    <Name>Project 01</Name>
    <File>Test.txt</File>
    <Integer_A>1</Integer_A>
    <Integer_B>2</Integer_B>
    <Status>Open</Status>
    <Description></Description>
    <Note></Note>
    </Project>
    </Projects>

    Here's the XSD file (XML Schema):

    <?xml version="1.0" ?>
    <xs:schema id="Projects" targetNamespace="projects.xsd"
    xmlns:mstns="projects.xsd" xmlns="projects.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    attributeFormDefault="qualified"
    elementFormDefault="qualified">

    <xs:element name="Projects" msdata:IsDataSet="true"
    msdata:EnforceConstraints="False">

    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="Project">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="S-ID" type="xs:integer"
    minOccurs="0" />
    <xs:element name="Name" type="xs:string" minOccurs="0" />
    <xs:element name="File" type="xs:string" minOccurs="0" />
    <xs:element name="Posted_By_User" type="xs:integer" minOccurs="0"
    />
    <xs:element name="Posted_For_User" type="xs:integer"
    minOccurs="0" />
    <xs:element name="Status" type="xs:string" minOccurs="0" />
    <xs:element name="Description" minOccurs="0" />
    <xs:element name="Date_Posted" type="xs:string" minOccurs="0" />
    <xs:element name="Date_Received" type="xs:string" minOccurs="0"
    />
    <xs:element name="Note" type="xs:string" minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    David Knipper Guest

  3. #3

    Default Re: DataGrid-DataView-XML-Sorting strings as numeric

    Here's a good way to do it...

    First... You need to create an XML schema file along with your xml file.

    Here's an example:

    Original XML File (example):

    <?xml version="1.0" encoding="utf-8" ?>
    <Projects xmlns="projects.xsd">
    <Project>
    <ID>1</ID>
    <Name>Project 01</Name>
    <File>Test.txt</File>
    <Integer_A>1</Integer_A>
    <Integer_B>2</Integer_B>
    <Status>Open</Status>
    <Description></Description>
    <Note></Note>
    </Project>
    </Projects>

    Here's the XSD file (XML Schema):

    <?xml version="1.0" ?>
    <xs:schema id="Projects" targetNamespace="projects.xsd"
    xmlns:mstns="projects.xsd" xmlns="projects.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    attributeFormDefault="qualified"
    elementFormDefault="qualified">
    <xs:element name="Projects" msdata:IsDataSet="true"
    msdata:EnforceConstraints="False">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="Project">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="S-ID" type="xs:integer"
    minOccurs="0" />
    <xs:element name="Name" type="xs:string" minOccurs="0" />
    <xs:element name="File" type="xs:string" minOccurs="0" />
    <xs:element name="Integer_A" type="xs:integer"
    minOccurs="0" />
    <xs:element name="Integer_B" type="xs:integer"
    minOccurs="0" />
    <xs:element name="Status" type="xs:string" minOccurs="0" />
    <xs:element name="Description" minOccurs="0"/>
    <xs:element name="Note" type="xs:string" minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Now when you use this XML file and schema in your datagrid... include
    the schema in your dataset along with the xml file. Do it somewhat like
    this...

    //... c#

    DataSet ds = new
    DataSet(); ds.ReadXmlSchema(Server.MapPath("projects.xsd")); ds.ReadXml
    (Server.MapPath("projects.xml"),XmlReadMode.InferS chema);
    DataView dv = new DataView(ds.Tables[0]);

    //...

    DG.DataSource = dv;
    DG.DataBind();

    //...



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    David Knipper Guest

Similar Threads

  1. Replies: 1
    Last Post: April 8th, 12:23 AM
  2. Replies: 0
    Last Post: August 11th, 01:16 AM
  3. Replies: 0
    Last Post: August 4th, 08:42 AM
  4. Replies: 0
    Last Post: July 15th, 11:03 PM
  5. #24652 [Com]: array keys that are strings but numeric behave incorrectly
    By Nico dot Laus dot 2001 at gmx dot de in forum PHP Development
    Replies: 0
    Last Post: July 15th, 05:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139