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

DataGrid Sort Expression for a date in format 'dd mmm yy'

Does anyone know the sort expression for a column that's data has been
returned in the format, eg '07 Jul 05'??

The sort expression {..:"dd mmm yy"} doesn't work ( if the column was
returned as '07-Mar-05' the expression {..:dd-MMM-yy} works OK

Second question, does anyone know hwo to return a date from SQL server
in the format '07-Mar-05', as this would be a workaround. At the moment
I'm using CONVERT(varchar(12),columnname,6 ) to return in format '07
Jul 05', but if I can't format that in the datagrid I suppose I could
return it in another way.

Whatever I do I need to see the MMM on the page, rather than a number
for the month.

Cheers all,
Bob

Nov 19 '05 #1
4 9585
Hi Bob,

The second part is easy using the DataFormatString attribute:
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
<columns>
<asp:boundcolumn DataField="final_appvl_dt"
SortExpression="final_appvl_dt" DataFormatString="{0:dd-MMM-yy}"
ReadOnly="True" HeaderText="Final Apprvl Date"
ItemStyle-Wrap="false"></asp:boundcolumn>

</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
dt.Columns.Add(New DataColumn _
("final_appvl_dt", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dr(4) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

"yer darn tootin" <bo*************@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Does anyone know the sort expression for a column that's data has been
returned in the format, eg '07 Jul 05'??

The sort expression {..:"dd mmm yy"} doesn't work ( if the column was
returned as '07-Mar-05' the expression {..:dd-MMM-yy} works OK

Second question, does anyone know hwo to return a date from SQL server
in the format '07-Mar-05', as this would be a workaround. At the moment
I'm using CONVERT(varchar(12),columnname,6 ) to return in format '07
Jul 05', but if I can't format that in the datagrid I suppose I could
return it in another way.

Whatever I do I need to see the MMM on the page, rather than a number
for the month.

Cheers all,
Bob


Nov 19 '05 #2
Hi Bob,

You can convert "07 Jul 05" to "07-Jul-05" by using
string.Replace() method:

string strDate = "07 Jul 05";
strDate = strDate.Replace(" ", "-");

HTH

Elton Wang
el********@hotmail.com

-----Original Message-----
Does anyone know the sort expression for a column that's data has beenreturned in the format, eg '07 Jul 05'??

The sort expression {..:"dd mmm yy"} doesn't work ( if the column wasreturned as '07-Mar-05' the expression {..:dd-MMM-yy} works OK
Second question, does anyone know hwo to return a date from SQL serverin the format '07-Mar-05', as this would be a workaround. At the momentI'm using CONVERT(varchar(12),columnname,6 ) to return in format '07Jul 05', but if I can't format that in the datagrid I suppose I couldreturn it in another way.

Whatever I do I need to see the MMM on the page, rather than a numberfor the month.

Cheers all,
Bob

.

Nov 19 '05 #3

Thanks for the replies, Ken and Elton. Always good to pick up some
stuff to investigate, novice that I am with this stuff.

Unfortunately, I think I may not have emphasised the exact nature of
the problem I was trying to solve.

I have a date column displayed in a datagrid which literally is in the
format 'dd mmm yy, eg it might be listing '07 Jan 05' ot '03 Jan 05'.
This is being returned from a SQL database sproc where I've used the
convert function on the date column, ie
convert(varchar(12),datecreated,6), which takes a date stored in the
format 2004-11-23 16:18:00 and changes it to '23 Nov 04' before
returning it back to the caller.
Behind the scenes, in the ASPX page's datagrid, I want to be able to
sort on this column, but as the date data on the form is in the format
'dd mmm yy' the Data formatting expression of {0:dd-MMM-yyyy} in the
datagrid for this column wouldn't sort it how I wanted, it was just
sorting by dd, numerically. I tried changing the expression to {0:dd
mmm yyyy} but it didn't seem to make a difference.

So I've taken the workaround option and am returning the date to the
form as '07-Jan-2005', rather than '07 Jan 05', so the sort expression
{0:dd-MMM-yyyy} works on that OK.

Hope this makes more sense now, if anyone has any suggestions.

Thanks again for the notes,
Bob

Nov 19 '05 #4
In your case, it's better to directly sort Date rather
than string. So my suggestion is that don't do any convert
to date string in SP, hence it's easy to sort date type
data. Then when showing those date type data in datagrid
format them to specific string type, using
DataFormatString as Ken's post.

Elton Wang

-----Original Message-----

Thanks for the replies, Ken and Elton. Always good to pick up somestuff to investigate, novice that I am with this stuff.

Unfortunately, I think I may not have emphasised the exact nature ofthe problem I was trying to solve.

I have a date column displayed in a datagrid which literally is in theformat 'dd mmm yy, eg it might be listing '07 Jan 05' ot '03 Jan 05'.This is being returned from a SQL database sproc where I've used theconvert function on the date column, ie
convert(varchar(12),datecreated,6), which takes a date stored in theformat 2004-11-23 16:18:00 and changes it to '23 Nov 04' beforereturning it back to the caller.
Behind the scenes, in the ASPX page's datagrid, I want to be able tosort on this column, but as the date data on the form is in the format'dd mmm yy' the Data formatting expression of {0:dd-MMM- yyyy} in thedatagrid for this column wouldn't sort it how I wanted, it was justsorting by dd, numerically. I tried changing the expression to {0:ddmmm yyyy} but it didn't seem to make a difference.

So I've taken the workaround option and am returning the date to theform as '07-Jan-2005', rather than '07 Jan 05', so the sort expression{0:dd-MMM-yyyy} works on that OK.

Hope this makes more sense now, if anyone has any suggestions.
Thanks again for the notes,
Bob

.

Nov 19 '05 #5

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

Similar topics

10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
3
by: Daniel M. | last post by:
I have a query that gets a string column containing a date, ex. 20040825. If I use the property builder to format the string to 08/25/2004 it does not work because it only accepts datetime columns....
0
by: Robert Brinson | last post by:
Hello all! I'm running .NET Framework 1.1 using VS.NET 2003. I've got a mystery with a DataGrid. Below is the definition of the DataGrid from my aspx page: </asp:datagrid><asp:datagrid...
0
by: Mo | last post by:
Hi, I'm getting an error: Input string was not in a correct format This happens when I try to sort a column. It seems that the sort event handler claims that the sort expression is not in...
2
by: Roger | last post by:
I have a datagrid with a column bound to a date field. Is there a way to format the date field?
2
by: Wayne Wengert | last post by:
I want to format a date field in a DataGrid column as mm/dd/yyyy. I am using the following code: <asp:DataGrid id="DataGrid1" AutoGenerateColumns="false" EnableViewState="False" runat="server">...
10
by: ruca | last post by:
Hi I want to format some columns of my DataGrid control. Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but when I show him in datagrid he comes with hours too. I...
7
by: Volodymyr Lozovoy | last post by:
Hi All, who suggest why subj do not affect on displayed result for date?
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
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: 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
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
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
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...
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...

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.