This is a migrated thread and some comments may be shown as answers.

Auto data type assign to gridview column

3 Answers 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul Bacci
Top achievements
Rank 1
Paul Bacci asked on 12 May 2008, 03:40 PM
Hi,

I am trying to get data from excel file to the grid at the runtime. The way I am doing this is that I get all data into untyped dataset and then bind it to the grid. The problem I am facing is that when data is bound to the grid if the data in first few rows of specific column is a number then it expects all the data in that column to be number, however it can contain string value as well. Is there a way to stop grid from automatically assigning data type to the column??

Thanks in advance for help.

3 Answers, 1 is accepted

Sort by
0
Par
Top achievements
Rank 1
answered on 12 May 2008, 07:41 PM
Hi,

Just to be more specific on this issue, what grid does is that it assigns datatype to the column depending on the first few entries of the column. So for example if the first few entries in column value contains all numbers, it interprets it as a column that can only take numeric data type and ignores all the string values that appears in dataset later on. It doesn't display string data into grid, and when I try to manually type it into grid it shows error that 'input string was not in correct format'. how can we prevent grid from doing this>? how can we stop it from assuming what data should me entered in to each column? can you please help me out with it.


0
Julian Benkov
Telerik team
answered on 14 May 2008, 03:04 PM
Hi Par,

RadGridView generates columns from a DataTable object automatically, based on the DataType property for each column in the DataTable object. This scenario applies for the case when RadGridView uses the DataSet or DataTable object for data source.

To change the type of a column in the DataTable, you must change its DataType to the desired type manually(in System.String or System.Int32 in your case) and then bind it to RadGridView.

Another solution is to set MasterGridViewTemplate's AutoGenerateColumns property to false and add all your columns manually to RadGridView. For each new added column, you must once again set the DataType property to be as the one in the DataTable object.

I hope this was helpful. If you have additional questions, please contact us.

 
Sincerely yours,
Julian Benkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Par
Top achievements
Rank 1
answered on 15 May 2008, 03:53 PM
Hi Julian,

Thanks for the reply. I guess it wasn't a telerik problem. Its mentioned in first post that I am getting data from Excel file to the dataset. Thats where the problem was. Thanks for your help.

Par
Tags
GridView
Asked by
Paul Bacci
Top achievements
Rank 1
Answers by
Par
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or