【问题标题】:Telerik GridView Datetime Column set to "" based on conditionTelerik GridView Datetime Column 根据条件设置为“”
【发布时间】:2015-12-07 02:29:30
【问题描述】:

GridView 中datetime 列的默认值为1/1/1900

如果值为 1/1/1900 我想要什么我希望单元格为空白。

我在这个环境中真的很陌生,所以请耐心等待。

这是我的代码:

    void SetDate()
    {
        GridViewDateTimeColumn ExpiryDate = this.gvItemReceiptDetails.Columns["ExpiryDate"] as GridViewDateTimeColumn;
        ExpiryDate.FormatString = "{0:M/d/yyyy}";
        ExpiryDate.FormatInfo = CultureInfo.CreateSpecificCulture("en-GB");
        ExpiryDate.NullValue = "";

    }

【问题讨论】:

  • 检查ItemDataBound()中的数据如何?
  • @un-lucky 我现在正在研究 cell_formatting。嗯,先生,你能给我举个例子吗?
  • @un-lucky 先生,我已经知道了。我只是在 cell_formatting 上进行操作...获取 datetime 列的值并检查该值是否为 1/1/1900..

标签: c# gridview telerik


【解决方案1】:

您可以使用 ItemDataBound 执行以下操作:

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    //Is it a GridDataItem
    if (e.Item is GridDataItem)
    {
        //Get the instance of the right type
        GridDataItem dataBoundItem = e.Item as GridDataItem;

        //Check the formatting condition
        if (dataBoundItem["ExpiryDate"].Text =="1/1/1900")
        {
           dataBoundItem["ExpiryDate"].Text="";
            //Customize more if needed...
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-05
    • 2019-06-11
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 2020-12-13
    相关资源
    最近更新 更多