locked
Remove Ear From My Gridview Column RRS feed

  • Question

  • User-807418713 posted

    Hello

    My Gridview coulm shows data like this for example

    01-Oct-2019

    05-Oct-2019

    11-Oct-2019

    11-Oct-2019

    14-Oct-2019

    But i want like this

    01-Oct 

    05-Oct 

    11-Oct 

    11-Oct 

    14-Oct 

    How to do so

    Thanking You

    Tuesday, November 19, 2019 10:24 AM

Answers

  • User3690988 posted

    If you have a BoundField use DataFormatString

    <asp:BoundField DataField="transaction_Date" HeaderText="transaction_Date" DataFormatString="{0:d-MMM}" />

    If it is a TemplateField, try something like this:

    <ItemTemplate>
     <asp:Label ID="Label1" runat="server" Text='<%# Bind("transaction_Date", "{0:d-MMM}") %>'></asp:Label>
    </ItemTemplate>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 19, 2019 12:17 PM

All replies

  • User-1780421697 posted

    You can use .ToString overload to perform formating.

    DateTime date1 = new DateTime(2008, 1, 2, 6, 30, 15);
     Console.WriteLine(date1.ToString("d-MMM"));
    Console.WriteLine(date1.ToString("d MMM"));

    Tuesday, November 19, 2019 11:40 AM
  • User3690988 posted

    If you have a BoundField use DataFormatString

    <asp:BoundField DataField="transaction_Date" HeaderText="transaction_Date" DataFormatString="{0:d-MMM}" />

    If it is a TemplateField, try something like this:

    <ItemTemplate>
     <asp:Label ID="Label1" runat="server" Text='<%# Bind("transaction_Date", "{0:d-MMM}") %>'></asp:Label>
    </ItemTemplate>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 19, 2019 12:17 PM
  • User-1038772411 posted

    Hello Gopi.MCA

    I had created demo.

    .aspx.cs page (Codebehind page)

                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("BirthDate", typeof(DateTime)) });
                dt.Rows.Add(1, "A", new DateTime(1967, 10, 1));
                dt.Rows.Add(2, "B", new DateTime(1975, 10, 5));
                dt.Rows.Add(3, "C", new DateTime(1965, 10, 11));
                dt.Rows.Add(4, "D", new DateTime(1968, 10, 11));
                dt.Rows.Add(5, "E", new DateTime(1968, 10, 14));
                GridView1.DataSource = dt;
                GridView1.DataBind();

    .aspx page

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="Id" HeaderText="Customer Id" ItemStyle-Width="100px" />
            <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="120px" />
            <asp:BoundField DataField="BirthDate" HeaderText="Birth Date" DataFormatString = "{0:dd-MMM}" ItemStyle-Width="120px" />
        </Columns>
    </asp:GridView>

    If you want to set more date format thenyou can use the website link : http://hamidseta.blogspot.com/2011/06/datetime-format-in-gridview.html

    If you want still any help please let us know.

    Thanks

    Tuesday, November 19, 2019 12:34 PM