GridViewDateTimeColumn and NullValue

2 posts, 0 answers
  1. Dario Concilio
    Dario Concilio avatar
    172 posts
    Member since:
    Apr 2016

    Posted 09 May 2016 Link to this post


    I have a DateTime field in my table that is nullable.

    How can I keep null value in my grid?

    I would show empty cell when date is null, and user could insert a date or cancel a date that already exists.

  2. Dess
    Dess avatar
    2166 posts

    Posted 09 May 2016 Link to this post

    Hello Potito,

    Thank you for writing.

    GridViewDateTimeColumn provides date entry and formatting for DateTime data types. It handles the null values as well. Here is a sample code snippet which result is illustrated in the attached gif file.
    public Form1()
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Date", typeof(DateTime));
        for (int i = 0; i < 20; i++)
            if (i % 3 == 0)
                dt.Rows.Add(i, "Data" + i, null);
            else if (i % 3 == 1)
                dt.Rows.Add(i, "Data" + i, DBNull.Value);
                dt.Rows.Add(i, "Data" + i, DateTime.Now.AddDays(i));
        this.radGridView1.DataSource = dt;
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

    I hope this information helps. Should you have further questions I would be glad to help.

    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top