Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrid-DataView-XML-Sorting strings as numeric

Reply
Thread Tools

DataGrid-DataView-XML-Sorting strings as numeric

 
 
Joe Rattz
Guest
Posts: n/a
 
      11-19-2003
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.
 
Reply With Quote
 
 
 
 
David Knipper
Guest
Posts: n/a
 
      11-20-2003
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"
xmlnss="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-comml-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 http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
David Knipper
Guest
Posts: n/a
 
      11-20-2003
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"
xmlnss="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-comml-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 http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
int to numeric numeric(18,2) ? jobs ASP .Net 2 07-22-2007 12:32 AM
Arithmetic overflow error converting numeric to data type numeric. darrel ASP .Net 4 07-19-2007 09:57 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
check if string contains numeric, and check string length of numeric value ief@specialfruit.be C++ 5 06-30-2005 01:08 PM
Dividing strings filled with numeric values M. Akkerman C++ 5 12-14-2003 12:21 AM



Advertisments