【问题标题】:dateformatting in gridview with date onlygridview 中的日期格式化,仅使用日期
【发布时间】:2014-03-19 03:58:09
【问题描述】:

在我的数据库sql server 中,有一个列名作为日期。我只插入日期。但我从该表中检索数据,然后用date 显示时间。但我只想要date。 看这里

这是我的gridview代码

  <asp:GridView ID="GridIssue" runat="server" CssClass="grid" AllowPaging="true" PageSize="8" OnPageIndexChanging="GridIssue_PageIndexChanging">
        <EmptyDataTemplate>
            <p style="margin-left: 10px;">No Book Has Been Issued Yet.</p>
        </EmptyDataTemplate>

    </asp:GridView>

如何从单元格中删除时间?

【问题讨论】:

    标签: c# asp.net sql-server database gridview


    【解决方案1】:

    你需要添加一个绑定了对应的 DateFormatString 的字段:

    <asp:BoundField DataField="DateFieldName" 
                    HeaderText="MyDateTime"
                    DataFormatString="{0:yyyy-MM-dd}"  />
    

    MSDN on DateFormatString

    【讨论】:

      【解决方案2】:

      尝试将 htmlencode 属性设置为 false,然后使用:

       <asp:BoundField DataField="action_issue_date" HeaderText="Date" SortExpression="action_yourdate" DataFormatString="{0:d}"  htmlencode="False">
      

      【讨论】:

        猜你喜欢
        • 2018-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        • 2017-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多