Answered GetType()

Anburaj Marikkani

New member
Joined
Jul 29, 2020
Messages
2
Programming Experience
3-5
Hi,

I have a class(MyClass) it is inherited from DataTable class.

Class MyClass : DataTable {
}

And I bind this class to my grid. In our source, there is a condition which checks

grid.Datasource.GetType.Name=="DataTable"

But in my case, the Datasource type name has MyClass then how can I achieve without modifying the condition
 
The condition only allows "DataTable" and no inheritance. If condition can't change then you can only use DataTable and not other class.
 
And if the condition can be changed, it can be changed to
C#:
typeof(DataTable).IsAssignableFrom(grid.DataSource.GetType())
 
I would recommend exercising extreme caution about restricting the type to just DataTable and it's descendants. See the documentation for the list of other types supported by the DataSource property:
 

Latest posts

Back
Top Bottom