This is a migrated thread and some comments may be shown as answers.

conditional blank for datetime value

3 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 16 Sep 2011, 03:50 PM
Hi,

I have a datetime column within my grid. I would like to set the value within this column to be empty anytime that the
datetime = 1/1/0001 12:00:00 AM

The row will still retain all other values. please let me know of anyways to do this.

thanks,
Minh Bui

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Sep 2011, 06:21 AM
Hello Minh,

Try the following approach to achieve your scenario.
C#:
protected void grdEmail_ItemDataBound(object sender, GridItemEventArgs e)
  {
 
    if (e.Item is GridDataItem)
     {
       DateTime test = new DateTime(0001, 01, 01);
       Nullable<DateTime> _myDateTime;
       _myDateTime = Convert.ToDateTime(s);
         if (_myDateTime == test)
           {
             item["MyDate"].Text = "";
           }
     }
  }

Thanks,
Shinu.
0
Minh
Top achievements
Rank 1
answered on 19 Sep 2011, 06:48 AM
Hi,

I'm getting s does not exist in this context from the following line

_myDateTime = Convert.ToDateTime(s);

thanks,
Minh Bui
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Sep 2011, 07:38 AM
Hello,

<telerik:GridDateTimeColumn DataField="customdate" HeaderText="customdate" UniqueName="customdate">
                   </telerik:GridDateTimeColumn>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = e.Item as GridDataItem;
           DateTime dt;
           if (DateTime.TryParse(item["customdate"].Text,out dt))
           {
               if (dt == new DateTime())
               {
                   item["customdate"].Text = string.Empty;
               }
 
           }
       }
   }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Minh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Minh
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or