Reputation: 71
I'd like to display the abbreviated
name of the month in the gridview
for example 11/Aug/2015
<asp:GridView ID="Gridsrev" runat="server" CssClass="table table-bordered text-nowrap" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ButtonType="Button" ControlStyle-CssClass="btn btn-primary" HeaderText="Select" SelectText="Preview" ShowSelectButton="True"></asp:CommandField>
<asp:BoundField DataField="S.R.NO" HeaderText="S.R.NO" SortExpression="S.R.NO"></asp:BoundField>
<asp:BoundField DataField="Agrement ID" HeaderText="Agrement ID" SortExpression="Agrement ID"></asp:BoundField>
<asp:BoundField DataField="CUST_ID" HeaderText="CUST ID" SortExpression="CUST_ID"></asp:BoundField>
<asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer"></asp:BoundField>
<asp:BoundField DataField="Service Type" HeaderText="Service Type" SortExpression="Service Type"></asp:BoundField>
<asp:BoundField DataField="Service Date" HeaderText="Service Date" SortExpression="Service Date" DataFormatString="{0:dd/MMM/yyyy}"></asp:BoundField>
<asp:BoundField DataField="Next Service" HeaderText="Next Service" SortExpression="Next Service" DataFormatString="{0:dd/MMM/yyyy}"></asp:BoundField>
</Columns>
Upvotes: 0
Views: 267
Reputation: 1962
Just add htmlEncode and set it to true. Try this :
<asp:BoundField DataField="Service Date" HeaderText="Service Date" SortExpression="Service Date" HtmlEncodeFormatString="true" DataFormatString="{0:dd/MMM/yyyy}"></asp:BoundField>
<asp:BoundField DataField="Next Service" HeaderText="Next Service" SortExpression="Next Service" HtmlEncodeFormatString="true" DataFormatString="{0:dd/MMM/yyyy}"></asp:BoundField>
Upvotes: 1
Reputation: 29181
I've just tried using your DataFormatString
in my ASP.Net GridView, and it changed the date format to exactly what you were looking for:
<asp:BoundField DataField="StartDate" DataFormatString="{0:dd/MMM/yyyy}" HeaderStyle-Width="100px" />
This produced a column of dates in this format:
11.Jan.2013
(My language settings have full-stop as the date separator character.)
Perhaps this is an issue with your data ?
Upvotes: 0
Reputation: 71
If i'm not wrond you need to set htmlEncode=false for your BoundField with DataFormatString It will disable the encoding of html and use your DataFormatString
Upvotes: 1