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

databound grid view date/time

A databound grid is loaded with data, and column 1 is a date/time field in the database. By default, the datagrid displays this as a date field only and automatically brings in the datepicker. How can I eliminate the datepicker and instead just display the data''s date/time as a text? I changed the format to a textbox for that column, but it still displays it with the datepicker.

7 Replies

AD Administrator Syncfusion Team April 8, 2004 08:16 AM

Hi Kelly, Please try changing the cell type to textbox and set the format to include the both date and time. //format column so no dropdown GridStyleInfo style = this.gridDataBoundGrid1.Binder.InternalColumns[0].StyleInfo; style.CellType = "TextBox"; style.CellValueType = typeof(DateTime); style.Format = "MM/dd/yy HH:mm:ss:fff"; Here is a sample Regards, Jay N


AD Administrator Syncfusion Team April 8, 2004 09:16 AM

My project is in vb am I''m having trouble translating a line of code: style.CellValueType = typeof(DateTime); Dim style As New GridStyleInfo style = sfDatagrid.Binder.InternalColumn(0).StyleInfo style.CellType = "TextBox" Thanks!


AD Administrator Syncfusion Team April 8, 2004 10:59 AM

Hi Kelly, Sorry for the inconvenience. Here is the VB code. ''format column so no dropdown Dim style As GridStyleInfo = Me.gridDataBoundGrid1.Binder.InternalColumns(0).StyleInfo style.CellType = "TextBox" style.CellValueType = GetType(DateTime) style.Format = "MM/dd/yy HH:mm:ss:fff" Here is the VB sample Regards, Jay N


AD Administrator Syncfusion Team April 8, 2004 11:40 AM

Jay, Thanks for the VB sample. I''m getting an error on line: Dim style As GridStyleInfo = Me.sfDatagrid.Binder.InternalColumns(1).StyleInfo Error message: =================== An unhandled exception of type ''System.ArgumentOutOfRangeException'' occurred in mscorlib.dll Additional information: Index was out of range. Must be non-negative and less than the size of the collection. =================== I''ve tried to use a different col index number to see if maybe my index was off. Basically, the dataset is first col: text type second col: date/time (this is the col that I''d wanted to eliminate the datepicker) My datagrid is built by running a sql statement that returns an un-typed dataset but I''ve also removed a few columns from the dataset. ds.Tables(0).Columns.Remove("ColName") myDatatGrid.datasource = ds.tables(0)


AD Administrator Syncfusion Team April 8, 2004 03:37 PM

Hi Kelly, Before this line, try checking your datatable''s column count like ds.tables(0).Columns.Count Dim style As GridStyleInfo = Me.sfDatagrid.Binder.InternalColumns(1).StyleInfo. I guess the indexer digit is greater than the columns present in the table. Or you can try giving the columnname instead of the integer to see if that helps. Dim style As GridStyleInfo = Me.sfDatagrid.Binder.InternalColumns("Colname").StyleInfo. Regards, Jay N


AD Administrator Syncfusion Team April 12, 2004 07:06 AM

It turns out that the column index of the date column is -1. myDataGrid.NameToColIndex("myDateColName") Any thoughts on why the index would be a negative number? Thanks.


AD Administrator Syncfusion Team April 12, 2004 07:45 AM

The -1 means that it cannot find the name, "myDateColName". This is case sensitive. Is there a column in your DataTable whose column name is exactly "myDateColName"? Have you explicitly added GridBoundColumns to the Me.sfDatagrid.GridBoundColumns collection? If so, instead of using Me.sfDatagrid.Binder.InternalColumns, use Me.sfDatagrid.GridBoundColumns. (This would explain why the column could not be found in sfDatagrid.Binder.InternalColumns).

Loader.
Live Chat Icon For mobile
Up arrow icon