| | |
format bound field in gridview
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 144
Reputation:
Solved Threads: 0
hi
a have a gridview with datafield column which is bound to a datetime column.
i want the grid column to show the date when the day is first, like this: 24/2/2009
i tried the following format:
but the grid is still shows the date when the month is first.
where was i wrong ?
a have a gridview with datafield column which is bound to a datetime column.
i want the grid column to show the date when the day is first, like this: 24/2/2009
i tried the following format:
asp Syntax (Toggle Plain Text)
DataFormatString="{0:dd/MM/YYYY}"
but the grid is still shows the date when the month is first.
where was i wrong ?
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
the total example is this :
Default.aspx :
Default.aspx.cs :
Default.aspx :
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="PKID" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."> <Columns> <asp:BoundField DataField="PKID" HeaderText="PKID" ReadOnly="True" SortExpression="PKID" /> <asp:BoundField DataField="date" DataFormatString="{0:dd/MM/yyyy}" HeaderText="date" SortExpression="date" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:denemeConnectionString1 %>" DeleteCommand="DELETE FROM [Table1] WHERE [PKID] = @PKID" InsertCommand="INSERT INTO [Table1] ([date]) VALUES (@date)" ProviderName="<%$ ConnectionStrings:denemeConnectionString1.ProviderName %>" SelectCommand="SELECT [PKID], [date] FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [date] = @date WHERE [PKID] = @PKID"> <DeleteParameters> <asp:Parameter Name="PKID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter DbType="Date" Name="date" /> </InsertParameters> <UpdateParameters> <asp:Parameter DbType="Date" Name="date" /> <asp:Parameter Name="PKID" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> </form> </body> </html>
Default.aspx.cs :
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Nov 2007
Posts: 144
Reputation:
Solved Threads: 0
i tryed it the way you suggested with small letters:
DataFormatString="{0:dd/MM/yyyy}"
it still doesnot work.
my full code line is:
DataFormatString="{0:dd/MM/yyyy}"
it still doesnot work.
my full code line is:
asp Syntax (Toggle Plain Text)
<asp:BoundField DataField="date" DataFormatString="{:dd/MM/yyyy}" HeaderText="date" />
•
•
Join Date: Dec 2008
Posts: 104
Reputation:
Solved Threads: 18
The problem is the by default, the HtmlEncode property of the boundfield attribute is set to True. This helps prevent cross-site scripting attacks and malicious content from being displayed. Microsoft recommends that the HtmlEncode attribute be enabled whenever possible.
The problem is that if this field is enabled, you can not pass format information to the boundfield control. To solve this issue simply set HtmlEncode to false
Try this:
The problem is that if this field is enabled, you can not pass format information to the boundfield control. To solve this issue simply set HtmlEncode to false
Try this:
asp Syntax (Toggle Plain Text)
<asp:BoundField DataField="date" DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false" HeaderText="date" />
Still not resolved??????????
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
•
•
Join Date: Apr 2008
Posts: 114
Reputation:
Solved Threads: 6
Please mark this post as 'Solved' if it has helped and fixed your issue.
•
•
Join Date: Nov 2006
Posts: 4
Reputation:
Solved Threads: 0
Hi
try this example:
try this example:
asp.net Syntax (Toggle Plain Text)
<asp:BoundField DataField=”date_from” HeaderText=”DateApply” HeaderStyle-Width =”350px” DataFormatString=”{0:MM/dd/yyyy}” HtmlEncode=”false”> //—–another way <asp:TemplateField HeaderText=”Date Submission” SortExpression=”DateSubmission”> <ItemTemplate> <asp:Label ID=”Label1″ runat=”server” Text=’<%# Bind(”DateSubmission”, “{0:dd/MM/yyyy}”) %>’></asp:Label> </ItemTemplate> <ItemStyle HorizontalAlign=”Center” /> </asp:TemplateField>
Last edited by peter_budo; Apr 25th, 2009 at 5:17 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Regards,
Nil
"If you like me raise your hand, if not raise your standard"
Nil
"If you like me raise your hand, if not raise your standard"
ONE CAN READ THE BELOW POST:
http://shawpnendu.blogspot.com/2009/...olumns-in.html
http://shawpnendu.blogspot.com/2009/...olumns-in.html
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: To search records
- Next Thread: ASP Site crashes after sitting idle for 30 minutes.
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






