Issue with DataFormatString...

R

Roy

Hey all,

Ok, I have a boundcolumn in a datagrid which displays a smalldatetime
field from a table. Behold:

<asp:BoundColumn DataField="final_appvl_dt"
SortExpression="final_appvl_dt" DataFormatString="{0:MMM-dd-yyyy}"
ReadOnly="True" HeaderText="Final Apprvl Date"
ItemStyle-Wrap="false"></asp:BoundColumn>

But the DataFormatString part isn't working as I expect. There's no
error and the date follows the format I specified (i.e., Jan 21 1950),
but the time is still displayed? How can I make the time go away?

Thanks!
 
K

Ken Cox [Microsoft MVP]

Hi Roy,

It seems to be working here just fine. Here's the repro code that I used,
including one without format:

<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
<columns>
<asp:boundcolumn DataField="final_appvl_dt"
SortExpression="final_appvl_dt" DataFormatString="{0:MMM-dd-yyyy}"
ReadOnly="True" HeaderText="Final Apprvl Date"
ItemStyle-Wrap="false"></asp:boundcolumn>
<asp:boundcolumn
DataField="final_appvl_dt" SortExpression="final_appvl_dt"
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

Ken
Microsoft MVP [ASP.NET]
Toronto
 
R

Roy

Hmmm.

I have no clue what I could be doing wrong then... Cleary it must be
something to do with the code behind page and not my aspx, yet I'm
clueless as to what.
 
K

Ken Cox [Microsoft MVP]

Hi Roy,

If you create another page using just the code that I posted, does it work
for you? Is there something strange in the computer's system date settings?

Ken
 
G

Guest

hi

This should work when that field should be in database as Datetime datatype
or u should return as datatime datatype when u're write a query.

by
gabi([email protected] or (e-mail address removed))
 
G

Guest

hi

This should work when that field should be in database as Datetime datatype
or u should return as datatime datatype when u're write a query.

by
gabi([email protected] or (e-mail address removed))
 
G

Guest

hi

This should work when that field should be in database as Datetime datatype
or u should return as datatime datatype when u're write a query.

by
gabi([email protected] or (e-mail address removed))
 
G

Guest

hi

This should work when that field should be in database as Datetime datatype
or u should return as datatime datatype when u're write a query.

by
gabi([email protected] or (e-mail address removed))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top