字符串不被识别为日期时间格式asp.net?

时间:2014-01-07 13:52:54

标签: c# asp.net user-controls calendarextender

 objRA_Campaigns.StartDate = DateTime.ParseExact(tbAgentsAgentComparisonByQuestionaireFrom.Text, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None);

asp.net日历扩展程序

<td style="padding-top: 5px; *padding-top: 3px; padding-left: 2px;" valign="middle">
                                <asp:TextBox ID="tbAgentsAgentComparisonByQuestionaireFrom" runat="server" CssClass="textBoxStyle"
                                    meta:resourcekey="tbAgentsAgentComparisonByQuestionaireFromResource1" 
                                    Width="282px"></asp:TextBox>
                                <asp:ImageButton ID="imgDateCampaignStart" runat="server" CssClass="imgbutton" ImageUrl="~/Images/Calendar.png"
                                    meta:resourcekey="imgDateCampaignStartResource1" />
                                <cc1:CalendarExtender ID="calAgentsAgentComparisonByQuestionaireFrom" runat="server"
                                    Format="dd-MM-yyyy" PopupButtonID="imgDateCampaignStart" TargetControlID="tbAgentsAgentComparisonByQuestionaireFrom"
                                    Enabled="True">
                                </cc1:CalendarExtender>
                            </td>

异常是字符串不是日期时间格式。

1 个答案:

答案 0 :(得分:4)

您的CalendarExtender格式为dd-MM-yyyy,您将其解析为yyyy/MM/dd HH:mm:ss。两种格式都应匹配,以便解析。