We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Setting the date format in a data bound grid

Hi, I have a databound grid and the data source has a DateTime column. By default the grid only displays the date and not the time (and the date selection control). I tried to set the format of the column in the model; however, that had no effect. What do I need to do? m_gridData.DataSource = m_dsData.Tables[0].DefaultView; m_gridData.Model.ColStyles["DateStamp"].CellValueType = typeof(DateTime); m_gridData.Model.ColStyles["DateStamp"].Format = "HH:mm MM/dd/yy"; Is the code snipit... originally I didn''t have the CellValueType call in there but thought maybe that explicitly setting the type might help; however, it didn''t. Thank you in advance, Jon

2 Replies

AD Administrator Syncfusion Team August 27, 2004 11:05 AM

To set style properties on a column in a GridDataBoundGrid, you use the GridBoundColumn.StyleInfo object instead of the ColStyle object used for GridControl. So, try GridStyleInfo style = m_gridData.Binder.InternalColumns["DataStamp"].StyleInfo; style.CellValueType = typeof(DateTime); style.Format = "HH:mm MM/dd/yy"; if you have not explicitly added GridBoundColumns to your grid. If you have added GridBoundCOlumns, use: GridStyleInfo style = m_gridData.GridBoundColumns["DataStamp"].StyleInfo; style.CellValueType = typeof(DateTime); style.Format = "HH:mm MM/dd/yy";


JO Jon August 27, 2004 11:38 AM

Thank you for the quick response! Jon

Loader.
Live Chat Icon For mobile
Up arrow icon