c# 在转发器控件中使用 Calendar.SelectedDate,但月份给了我“00”

c# use Calendar.SelectedDate in a repeater control, but month is giving me "00"

我正在尝试使用 asp.net 制作网络表单。 单击链接按钮时(在中继器内),应该会弹出一个日历。在日历上选择的日期应该填写文本框 "start date".

这是 Repeater1 中的一项:

<td>
      <asp:TextBox runat="server" ID="txtStart" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>' />
      <asp:LinkButton ID="btnCalendar" runat="server" 
      CssClass="btn btn-xs"OnClick="ShowCalendar">
      <span aria-hidden="true" class="glyphicon glyphicon-calendar"></span>
      </asp:LinkButton>
</td>

在所有其他项目之后,这是日历:

 <asp:Calendar ID="Calendar1" runat="server" Visibile="false"  SelectionMode="Day" onselectionchanged="Calendar1_SelectionChanged">
                  </asp:Calendar>

后面的代码:

protected void Calendar1_SelectionChanged(object sender, EventArgs e){
    if (Repeater1.Items.Count == 1)
    {
        TextBox txtStart = (TextBox)Repeater1.Items[0].FindControl("txtStart");
        DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;

        txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");
    }

这段后面的代码只是将文本添加到转发器的第一项

我的问题是:

Calendar 的 SelectedDate 为我提供了正确的年份和日期,但为我提供了月份值“00”

This is the link to a screenshot of the part of my webform which is problematic

谢谢!

只需更改行

 txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");

 txtStart.Text = Calendar1.SelectedDate.ToString("yyyyMMdd");