Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1175
Object Binding to Grid
posted

Hi 

I have a Class which has three properties, one of them is of datetime type. wheni assign this class's instance to my Grid, It shows 01/01/0001 defaultdate time in datetime type columns. How to avoid it. i want keep this column empty. I also dont want to set its DefaultValue to current date.

 

Regards 

Asad Naeem 

 

 

  • 469350
    Offline posted

    Hi Asad,

        If the property on your object is a DateTime, then it cannot store a null. This has nothing to do with the grid, this is a limitation of the DataTime data type in DotNet.

        What a DataTable does in a case like this is it uses type Object for all fields. That way it can hold DBNull or a real value. So if your object needs to hold nulls, you might want to consider changing the property to an Object type. If you are using CLR2, you might also be able to use a NullableDateTime, instead of DateTime. 

        If you can't change the Data type of the property, then maybe you could use an unbound column in the grid and hide the "real" column. Or maybe you can acheive what you want using a DataFilter.