Tuesday, November 1, 2011

InfoPath 2010 - Date Picker problem when SetVal from CodeBehind

Recently we came across a problem in InfoPath 2010 DateTime Control. When we assign a value in code-behind, the text box is marked red and asking for a valid date. However the date was valid and when we type the same date, it accept the same date. The assignment was as follows in code behind which produces the error

MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:grpFeeDetails/my:dateDPO", NamespaceManager).SetValue(l_oDateTimeDateDPO.ToShortDateString());

Identified Problem
Basically the issue is with the format of the date. When we use ToShortDateString, then the format is not compatible with the InfoPath 2010 Date Format.

To resolve this issue we used the following code

MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:txtDOB", NamespaceManager).SetValue(l_oDateTimeDOB.ToString("yyyy-MM-dd"));

The Important Point is this DateTime Format

Thanks to this post which help us to resolve this issue
InfoPath 2010 date and time picker control basics

1 comment:

  1. Thanks so much. Was in this exact prb and your solution worked, even 3 years later...:)