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 01:16 PM UTC

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 02:16 PM UTC

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 03:59 PM UTC

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 04:40 PM UTC

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 08:37 PM UTC

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 12:06 PM UTC

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 12:45 PM UTC

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).

Live Chat Icon For mobile
Up arrow icon