473,831 Members | 2,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting Datefield in a DataView

2 New Member
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.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{


if (!Page.IsPostBa ck)
{
Session["SortExpression "] = "";
Session["SortDirect ion"] = "";
}
SDU.Service_Cla ss.DataService ds =
new SDU.Service_Cla ss.DataService( Request.Applica tionPath,
"ProMan", SDU.Service_Cla ss.DataService. QueryType.STORE D_PROC,
"p_get_projects ");
if (ds.ExecuteComm and(30))
{
Session["MyProjects "] = ds.GetData.Tabl es[0];
gProjects.DataS ource = (DataTable)Sess ion["MyProjects "];
gProjects.DataB ind();
foreach (GridViewRow row in gProjects.Rows)
{
//row.Cells.
}
}
gProjects.RowSt yle.Height = 20;
{


String expression = "";
SortDirection direction;


}
}
protected void gProjects_Sorti ng(object sender,
GridViewSortEve ntArgs e)
{
DataView dv = new DataView((DataT able)Session["MyProjects "]);
string direction;
if (Session["SortExpression "].ToString() == e.SortExpressio n)
{
if (Session["SortDirect ion"].ToString() == "ASC")
{
direction = "DESC";
}
else
{
direction = "ASC";
}
}
else
{
direction = "ASC";
}


dv.Sort = e.SortExpressio n + " " + direction;
gProjects.DataS ource = dv;
gProjects.DataB ind();
Session["SortExpression "] = e.SortExpressio n;
Session["SortDirect ion"] = direction;
}
Jan 11 '07 #1
2 1398
kenobewan
4,871 Recognized Expert Specialist
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
WandaLL
2 New Member
I'm using a GridView and I have a date column and the dates are being pulled from a database:

<asp:BoundFie ld DataField="DueD ate" 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
1788
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 variable and then rebind to it for each page (which works). I'd also like to be able to sort any of the columns of the datagrid, so I do this using a dataview as shown below triggered from the normal Grid_SortCommand event :
9
2591
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 DataView. (I'm writing in C# with the v1.1.4322 of the .NET Framework, in Window2K server"). First of all, here are the two methods I have used in order to apply the sorting property to the DataView 1. Simply defining the sort order and colum DataView...
11
16386
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 applications that see the results as xml don't have to fiddle around and sort it themselves later). I have tried sorting a dataview and adding that dataview's table to the dataset but the results don't remain sorted. The only way I can see to do...
12
2395
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 field... This grid displayes results based on users search.. public static int numberDiv; private void Page_Load(object sender, System.EventArgs e) {
2
945
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 datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
4
10041
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 have a .getxml method (unlike the dataset). any ideas? thanks.
1
2354
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 page. i.e. If I have: IntegerValue StringValue CurrencyValue 0 Item 0 0 1 Item 1 1.23
4
11165
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 ReportTable As System.Data.DataTable = New System.Data.DataTable("SendTo") The ReportTable is populated row by row by data gotten back from the
1
1161
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 and paging portions won't. If I just call the DisplayData() method then the Edit portion doesn't work. I found out that when sorting the sorting value doesn't persist and I need to store it elsewhere when doing postbacks, but the code below is already...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10534
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9317
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5620
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3964
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.