473,395 Members | 1,631 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.

Date format in datagrid

What must I do to overcome a problem with my dates becoming formatted as
"2/22/2525 12:00:00 AM" in the datagrid? I want to handle all dates as
short string of format "2/22/2525." Otherwise when I run the update routine
SQL (set start_date = "2/22/2525 12:00:00 AM") does not work while short
string (set date = '2/22/2525') does work. See update routine below:

Private Sub MarketingDataGrid_UpdateCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
MarketingDataGrid.UpdateCommand

Dim ErrorMessage As String = Session("ErrorMessage")
Dim ad_nameText As TextBox = CType(e.Item.Cells(3).Controls(0),
TextBox)
Dim advertisement_name As String = ad_nameText.Text
Dim start_dateText As TextBox = CType(e.Item.Cells(4).Controls(0),
TextBox)
Dim start_date As String = start_dateText.Text
Dim expiration_dateText As TextBox =
CType(e.Item.Cells(5).Controls(0), TextBox)
Dim expiration_date As String = expiration_dateText.Text
Dim ad_typeText As TextBox = CType(e.Item.Cells(6).Controls(0),
TextBox)
Dim ad_type As String = ad_typeText.Text
Dim advertiserText As TextBox = CType(e.Item.Cells(7).Controls(0),
TextBox)
Dim advertiser As String = advertiserText.Text
Dim advertisement_descriptionText As TextBox =
CType(e.Item.Cells(8).Controls(0), TextBox)
Dim advertisement_description As String =
advertisement_descriptionText.Text
Dim source_id As String = Session("source_id")
Try
baseconnection.Close()
BICDataAdapter.UpdateCommand = ucommand
BICDataAdapter.UpdateCommand.Connection = baseconnection
baseconnection.ConnectionString = ConnectString
BICDataAdapter.UpdateCommand.CommandText = "Update Marketing set
advertisement_name = '" & advertisement_name & _
"',start_date = '" & start_date & "',expiration_date = '" &
expiration_date & "',ad_type = '" & ad_type & _
"',advertiser = '" & advertiser & "',advertisement_description =
'" & advertisement_description & _
"' where source_id = " & source_id
baseconnection.Open()
BICDataAdapter.Fill(BICDataSet, "marketing")
MarketingDataGrid.DataSource = BICDataSet.Tables("MARKETING")
MarketingDataGrid.DataBind()

--
Derek V. Taylor
UCI Brain Imaging Center
Apr 6 '06 #1
2 5127
Well of course you could bind with a SELECT statement instead of
directly to the table, and format the dates in your SELECT statement.
Or, handle the data appropriately on the grid.DataItemBound event,
which gives your row and cell level access as the grid is being
populated.

Apr 6 '06 #2
Hi Derek,

You probably want to do your formatting in the datagrid in a bound column
using dataformatstring.

That way, you keep the data and its presentation as separate issues. Here's
the idea:

<asp:datagrid id="MarketingDataGrid" runat="server">
<columns>
<asp:boundcolumn datafield="start_date"
dataformatstring="{0:d/M/yyyy}" headertext="Date and Time">
</asp:boundcolumn>
</columns>
</asp:datagrid>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

"Derek Vincent" <De**********@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
What must I do to overcome a problem with my dates becoming formatted as
"2/22/2525 12:00:00 AM" in the datagrid? I want to handle all dates as
short string of format "2/22/2525." Otherwise when I run the update
routine
SQL (set start_date = "2/22/2525 12:00:00 AM") does not work while short
string (set date = '2/22/2525') does work. See update routine below:

Private Sub MarketingDataGrid_UpdateCommand(ByVal source As Object, ByVal
e
As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
MarketingDataGrid.UpdateCommand

Dim ErrorMessage As String = Session("ErrorMessage")
Dim ad_nameText As TextBox = CType(e.Item.Cells(3).Controls(0),
TextBox)
Dim advertisement_name As String = ad_nameText.Text
Dim start_dateText As TextBox = CType(e.Item.Cells(4).Controls(0),
TextBox)
Dim start_date As String = start_dateText.Text
Dim expiration_dateText As TextBox =
CType(e.Item.Cells(5).Controls(0), TextBox)
Dim expiration_date As String = expiration_dateText.Text
Dim ad_typeText As TextBox = CType(e.Item.Cells(6).Controls(0),
TextBox)
Dim ad_type As String = ad_typeText.Text
Dim advertiserText As TextBox = CType(e.Item.Cells(7).Controls(0),
TextBox)
Dim advertiser As String = advertiserText.Text
Dim advertisement_descriptionText As TextBox =
CType(e.Item.Cells(8).Controls(0), TextBox)
Dim advertisement_description As String =
advertisement_descriptionText.Text
Dim source_id As String = Session("source_id")
Try
baseconnection.Close()
BICDataAdapter.UpdateCommand = ucommand
BICDataAdapter.UpdateCommand.Connection = baseconnection
baseconnection.ConnectionString = ConnectString
BICDataAdapter.UpdateCommand.CommandText = "Update Marketing
set
advertisement_name = '" & advertisement_name & _
"',start_date = '" & start_date & "',expiration_date = '" &
expiration_date & "',ad_type = '" & ad_type & _
"',advertiser = '" & advertiser & "',advertisement_description
=
'" & advertisement_description & _
"' where source_id = " & source_id
baseconnection.Open()
BICDataAdapter.Fill(BICDataSet, "marketing")
MarketingDataGrid.DataSource = BICDataSet.Tables("MARKETING")
MarketingDataGrid.DataBind()

--
Derek V. Taylor
UCI Brain Imaging Center

Apr 6 '06 #3

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

Similar topics

4
by: karunakar | last post by:
Hi All I was poplating Datagrid Datagrid has one of the column showing datetime field format iam showing DATE here not Necessary to populate the Time Frame Even my datebase column also...
7
by: Mike L | last post by:
This is for a Win form. SP sends back the PostMark date to my datagrid, shows proper date in datagrid. When user clicks on datagrid, the code sends the current row to text box. The text box...
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">...
4
by: Paul | last post by:
Hi, Everything went fine getting a short date format out of SQL into my DataGrid with this: <%# DataBinder.Eval(Container.DataItem, "Created", "{0:d}")%> Then I got too fancy in SQL and...
5
by: William Gower | last post by:
I have a datagrid that has a column that displays a date. The date is currently being displayed in a long format, I want to format it to display in short format. How do I do that in a datagrid?
4
by: yer darn tootin | last post by:
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...
1
by: Niclas Lindblom | last post by:
Hi, I have a bound column in a datagrid. The value in the database is using the SQL datetime format which gives both date and time. How do I configure the datagrid cell to only display the date...
1
by: Lurc | last post by:
Hi all, One field of Access table is date/time type, and format is long time. In VB.NET, as this table linked to a datagrid, a strange date 12-30-1899 is shown instead of the time expected....
6
by: yoshitha | last post by:
hi db : sql server 2000 lan : C#.net(ASp.Net) in my database table there are 2 fileds of data type datatime. in field 1 i'm storing date in field 2 i'm storing time.
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: 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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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...
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...

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.