473,387 Members | 1,516 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,387 software developers and data experts.

Sorting Datefield in a DataView

I have several columns which I've sorted but the Date Field sorts as a string
rather than as a date and I can't seem to figure out how to fix that.
Below is my code.

Thanks for your help.


public partial class MyProjects : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


if (!Page.IsPostBack)
{
Session["SortExpression"] = "";
Session["SortDirection"] = "";
}
SDU.Service_Class.DataService ds =
new SDU.Service_Class.DataService(Request.ApplicationP ath,
"ProMan", SDU.Service_Class.DataService.QueryType.STORED_PRO C,
"p_get_projects");
if (ds.ExecuteCommand(30))
{
Session["MyProjects"] = ds.GetData.Tables[0];
gProjects.DataSource = (DataTable)Session["MyProjects"];
gProjects.DataBind();
foreach (GridViewRow row in gProjects.Rows)
{
//row.Cells.
}
}
gProjects.RowStyle.Height = 20;
{


String expression = "";
SortDirection direction;


}
}
protected void gProjects_Sorting(object sender,
GridViewSortEventArgs e)
{
DataView dv = new DataView((DataTable)Session["MyProjects"]);
string direction;
if (Session["SortExpression"].ToString() == e.SortExpression)
{
if (Session["SortDirection"].ToString() == "ASC")
{
direction = "DESC";
}
else
{
direction = "ASC";
}
}
else
{
direction = "ASC";
}


dv.Sort = e.SortExpression + " " + direction;
gProjects.DataSource = dv;
gProjects.DataBind();
Session["SortExpression"] = e.SortExpression;
Session["SortDirection"] = direction;
}
Jan 11 '07 #1
2 1370
kenobewan
4,871 Expert 4TB
Are you formatting the date anywhere? Please give an example of the dates sorting by string, so that we know exaclty what you mean... :).
Jan 12 '07 #2
I'm using a GridView and I have a date column and the dates are being pulled from a database:

<asp:BoundField DataField="DueDate" HeaderText="Due Date" SortExpression="DueDate">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" Width="90" />
</asp:BoundField>
Jan 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave S | last post by:
Hi, I'm using a datagrid to display contents of a dataset and I've set the datagrid to allow paging and sorting. Rather than re-retrieve from the DB, I store the original dataset in a Session...
9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
11
by: Nikki | last post by:
Is it possible to sort a dataset rather than a dataview? I have a web service that returns a dataset which I would like to sort before returning it (this is so the sorting is standardised and so...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
4
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
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...
1
by: castron | last post by:
Hello All, I have a grid view that allows sorting, paging, editing, etc. Under On Load event, if I check: if(!IsPostBack){ DisplayData(); }, the Edit portion works fine. However, the Sorting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.