473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Gridview not sorting numeric or fomating because of datatype


I get my data from a basic xml file and make a datatable, and then bind it
to the gridview. I think it's not sorting or dataformatString correctly
because it thinks it's a string and not a number. Is there a way to tell
the gridview the value is a int?

This is how I bind the data:
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(new StringReader(xmlString));
DataTable table = aDataSet.Tables[0];
GridView1.DataSource = table;
GridView1.AllowSorting = true;
GridView1.DataBind();

Here is a bound field:
<asp:BoundField DataField="percentage" HeaderText="%"
SortExpression="percentage" HtmlEncode="False" DataFormatString="{0:P2}"
ReadOnly="True" />

All my value colums are sorted alphabetical

Jan 12 '07 #1
2 7415
Oh, sorry. I do the sorting manually because it comes from an XML file.
But I still can't get the formatting to work. I guess I can fix it in the
XML file.
"Cindy Lee" <ci******@hotmail.comwrote in message
news:uc**************@TK2MSFTNGP02.phx.gbl...
>
I get my data from a basic xml file and make a datatable, and then bind it
to the gridview. I think it's not sorting or dataformatString correctly
because it thinks it's a string and not a number. Is there a way to tell
the gridview the value is a int?

This is how I bind the data:
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(new StringReader(xmlString));
DataTable table = aDataSet.Tables[0];
GridView1.DataSource = table;
GridView1.AllowSorting = true;
GridView1.DataBind();

Here is a bound field:
<asp:BoundField DataField="percentage" HeaderText="%"
SortExpression="percentage" HtmlEncode="False" DataFormatString="{0:P2}"
ReadOnly="True" />

All my value colums are sorted alphabetical

Jan 12 '07 #2
This is my sorting function. How can I sort it numerically?
if (isPageIndexChanging)
{

dataView.Sort = string.Format("{0} {1}",
GridViewSortExpression, GridViewSortDirection);

}

else
{

dataView.Sort = string.Format("{0} {1}",
GridViewSortExpression, GetSortDirection());

}

"Cindy Lee" <ci******@hotmail.comwrote in message
news:eL**************@TK2MSFTNGP06.phx.gbl...
Oh, sorry. I do the sorting manually because it comes from an XML file.
But I still can't get the formatting to work. I guess I can fix it in the
XML file.
"Cindy Lee" <ci******@hotmail.comwrote in message
news:uc**************@TK2MSFTNGP02.phx.gbl...

I get my data from a basic xml file and make a datatable, and then bind
it
to the gridview. I think it's not sorting or dataformatString correctly
because it thinks it's a string and not a number. Is there a way to
tell
the gridview the value is a int?

This is how I bind the data:
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(new StringReader(xmlString));
DataTable table = aDataSet.Tables[0];
GridView1.DataSource = table;
GridView1.AllowSorting = true;
GridView1.DataBind();

Here is a bound field:
<asp:BoundField DataField="percentage" HeaderText="%"
SortExpression="percentage" HtmlEncode="False"
DataFormatString="{0:P2}"
ReadOnly="True" />

All my value colums are sorted alphabetical



Jan 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christian Hofmann | last post by:
Hello, I am using .Net Framework 2.0 Beta and for testing firefox. I disabled JavaScript in Firefox and now the gridview sorting and paging does not work. Evenery link is calling, for example,...
0
by: Dorte | last post by:
Hi, I use the gridview control to display data. I use a dataadapter to fill a datatable from an SQL server - the command is a stored procedure. Furthermore I have a couple of template columns...
1
by: tfsmag | last post by:
Hello, I have a function that returns a dynamically created gridview. This works fine, however it does not seem to be able to maintain state when adding sorting or paging to the gridview. Does...
5
by: yefei | last post by:
In my web design, I display records from a SQL DataBase according to some filters the GridView is defined with select commands and selest parameters however, I also want to display all records...
1
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all...
0
by: jobo | last post by:
Hey there, I'm having a problem getting sorting to work. Here's what the GridView looks like: "server" ID="updt1" Mode="Conditional">
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
3
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work....
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.