Default string for empty DateTime entry in Data Grid

Hi, I am using Data bound grid. One column is of type DateTime. In certain cases( Time field is Not applicable in certain cases.), I need to display string "N/A" in the cell. Is there any way to do the same. I can not make the column of type string and fill it on my own, as I need the sort facility for this column. Thanks in advance, Bidin

1 Reply

AD Administrator Syncfusion Team February 9, 2004 08:26 PM UTC

If you put a special DateTime value (say DateTime.MinValue) in these cells, then you can use these two events to handle this tasks. this.gridDataBoundGrid1.Model.QueryCellFormattedText += new GridCellTextEventHandler(gridModel_QueryCellFormattedText); this.gridDataBoundGrid1.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(gridModel_QueryCellInfo); private void gridModel_QueryCellFormattedText(object sender, GridCellTextEventArgs e) { if(e.Value.Equals(DateTime.MinValue)) { e.Text = "N/A"; e.Handled = true; } } private void gridModel_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if(e.Style.CellType == "MonthCalendar" && e.Style.CellValue.Equals(DateTime.MinValue)) { e.Style.ReadOnly = true; e.Style.Clickable = false; } }

Loader.
Up arrow icon