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
110
Using nullable datetime in grid datasource causes "Object reference not set to an instance of an object error"
posted

I am building a grid as posted in the code snippet. It appears that using a nullable datetime in my grid datasource is causing an object initialization run-time error. 

The reason I believe it has to do with the nullable datetime fields is that the grid will render just fine when I have these columns commented out. My guess is that any data point that has null in one of these columns is causing the grid to crash, because the datetime is not initialized. 

Of course, I could easily change the nullable datetime to a standard datetime object, but this would force the datetime objects to be initialized to a default value, the datetime minimum, and I obviously don't want this value in my grid.

Does anyone know how I can fix this?

@(Html.Infragistics().Grid(Model.Containers.AsQueryable())
            .ID(Model.HtmlElementId)
            .AutoGenerateColumns(false)
            .PrimaryKey("ContainerID")
            .Width("100%")
            .Columns(column =>
            {
                column.For(c => c.ContainerID).HeaderText("Container ID").Hidden(true);
                column.For(c => c.ContainerNumber).HeaderText("Container Number");
                column.For(c => c.Carrier).HeaderText("Carrier");
                column.For(c => c.ETA).HeaderText("ETA");
             /*column.For(c => c.DeliveryOrderSentDate).HeaderText("Delivery Order Sent");
                column.For(c => c.YardLocation).HeaderText("Yard Location");
                column.For(c => c.CargoReadyDate).HeaderText("Cargo Ready");*/
                column.For(c => c.Hold).HeaderText("Hold");
                //column.For(c => c.LastFreeDay).HeaderText("Last Free Day");
                column.For(c => c.Priority).HeaderText("Priority");
                /*column.For(c => c.MoveFirst).HeaderText("Move First");
                column.For(c => c.OutgateDate).HeaderText("Outgate");
                column.For(c => c.DeliveredDate).HeaderText("Delivered");
                column.For(c => c.ContainerEmptyDate).HeaderText("Container Empty");
                column.For(c => c.ExpectedReturnDate).HeaderText("Expected Return");
                column.For(c => c.ActualReturnDate).HeaderText("Actual Return");*/
                column.For(c => c.HasNotes).HeaderText("Notes").Template("");
            })
            .Features(f =>
             {
                 f.Filtering()
                     .Type(OpType.Local)
                     .CaseSensitive(false);
                 f.Paging()
                     .Type(OpType.Local)
                     .PageSize(10);
                 f.Sorting()
                     .Persist(false);
                 f.Updating()
                     .EditMode(GridEditMode.Row)
                     .EnableAddRow(false)
                     .EnableDeleteRow(false)
                     .ShowDoneCancelButtons(true);
             })
            .DataSource(Model.Containers.AsQueryable())
            .DataBind()
            .Render());

  • 29417
    Offline posted

    Hello Arden,

    Thank you for posting in our forum. 

    There shouldn’t be any problems with binding to a Nullable DateTime.

    Could you let me know which version of the product you are currently using? Also could you share the full stack trace of the error you are receiving? 

    I’ve attached a small sample for your reference that uses the latest version of 19.2 and defines a grid with one nullable date column. Please refer to it and let me know if it is similar to your scenario. If not then please feel free to modify it and send it back so that it reproduces your issue.

    2555.igGrid_BindingDates.zip

    I’m looking forward to your reply. 

    Regards,

    Maya Kirova