You can bind the very same field to two different bound columns (or whatever the column types you've used).
<telerik:GridBoundColumn
DataField="YourDateField"
UniqueName="CDate"
HeaderText="Date"
DataType="System.DateTime" DataFormatString="{0:yyyy-MM-dd}">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn
DataField="YourDateField"
UniqueName="CTime"
HeaderText="Time"
DataType="System.DateTime" DataFormatString="{0:HH:mm:ss}">
</telerik:GridBoundColumn>
Edit:
I think use of IEnumerable<T>
is the best approach to solve number of issues including data formatting and checking empty fields.
public class MyModel
{
public string UpdateDate {get;set;}
public string UpdateTime {get;set;}
//and add other properties which you need to be a part of grid
}
Write code to populate the IEnumerable<MyModel>
data-source which will be used by the grid.
var list = new List<MyModel>();
// Read one by one row/result from database and set value to
// an instance of MyModel
/* read/fetch row from database */
.....
var dbRow = /* fetch a row */
var model = new MyModel{ UpdateTime = "", UpdateDate=""};
if( dbRow.UpdateDateTime !=null )
{
model.UpdateDate = dbRow.UpdateDateTime.ToString("yyyy-MM-dd");
model.UpdateTime = dbRow.UpdateDateTime.ToString("HH:mm:ss");
}
list.Add( model );
...
...
and finally bind the list
data source to your Grid
control.
SO Thread - How Handle Null Values(In Columns) In Telerik RadGrid?
Update suggested by OP
Below code is also working fine to check the null/default values before display it into RadGrid:
protected void GridReport_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if (item["ScanDate"].Text == "01/01/1900")
{
item["ScanDate"].Text = "";
}
if(item["ScanTime"].Text == "00:00:00 AM")
{
item["ScanTime"].Text = "";
}
}
}