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

GridViewDateTimeColumn and NullValue

1 Answer 270 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dario Concilio
Top achievements
Rank 2
Dario Concilio asked on 09 May 2016, 08:26 AM

Hi,

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.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 May 2016, 09:11 AM
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()
{
    InitializeComponent();
 
    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);
        }
        else
        {
            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.

 Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Dario Concilio
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or