日历扩展器 SelectedDate Null

发布于 2024-11-10 15:06:03 字数 3375 浏览 0 评论 0原文

我有一个日历扩展程序“addHoliday”,但每次我选择一个值并尝试在其背后的代码中检索该值时,该值都是空的。我不知道为什么会这样。

<asp:Table runat="server">
                <asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">Day:</asp:TableHeaderCell><asp:TableCell>
                <asp:DropDownList ID="ddlAddDay" runat="server">
                  <asp:ListItem Text="Sunday" Value="0"></asp:ListItem>
                  <asp:ListItem Text="Monday" Value="1"></asp:ListItem>
                  <asp:ListItem Text="Tuesday" Value="2"></asp:ListItem>
                  <asp:ListItem Text="Wednesday" Value="3"></asp:ListItem>
                  <asp:ListItem Text="Thursday" Value="4"></asp:ListItem>
                  <asp:ListItem Text="Friday" Value="5"></asp:ListItem>
                  <asp:ListItem Text="Saturday" Value="6"></asp:ListItem>
                </asp:DropDownList>
                    </asp:TableCell></asp:TableRow><asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">Holiday Date:</asp:TableHeaderCell><asp:TableCell>
                    <asp:TextBox runat="server" ID="addHolidayBox" AutoPostBack="true" /><asp:CalendarExtender runat="server" ID="addHoliday" Animated="true" TargetControlID="addHolidayBox" /></asp:TableCell></asp:TableRow><asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">Start Time:</asp:TableHeaderCell><asp:TableCell>

                        <asp:DropDownList ID="addStartTimeHour" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addStartTimeMin" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addStartTimeAmPm" runat="server">
                            <asp:ListItem>AM</asp:ListItem>
                            <asp:ListItem>PM</asp:ListItem>
                        </asp:DropDownList>

                    </asp:TableCell></asp:TableRow><asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">End Time:</asp:TableHeaderCell><asp:TableCell>

                    <asp:DropDownList ID="addEndTimeHour" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addEndTimeMin" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addEndTimeAmPm" runat="server">
                            <asp:ListItem>AM</asp:ListItem>
                            <asp:ListItem>PM</asp:ListItem>
                        </asp:DropDownList>

              </asp:TableCell></asp:TableRow><asp:TableRow>
              <asp:TableCell></asp:TableCell><asp:TableCell><asp:Button ID="btnAddHours" runat="server" Text="Add Hours" OnClick="btnAddHours_Click" /></asp:TableCell>  
      </asp:TableRow>

C#

        protected void btnAddHours_Click(object sender, EventArgs e)
    {
        hoursDataSource.InsertParameters["HolidayDate"].DefaultValue = addHoliday.SelectedDate.Value.ToString();
    }

I have a calendar extender "addHoliday", but every time I select a value and try to retrieve that value in the code behind it's null. I'm not sure why this would be.

TABLE

<asp:Table runat="server">
                <asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">Day:</asp:TableHeaderCell><asp:TableCell>
                <asp:DropDownList ID="ddlAddDay" runat="server">
                  <asp:ListItem Text="Sunday" Value="0"></asp:ListItem>
                  <asp:ListItem Text="Monday" Value="1"></asp:ListItem>
                  <asp:ListItem Text="Tuesday" Value="2"></asp:ListItem>
                  <asp:ListItem Text="Wednesday" Value="3"></asp:ListItem>
                  <asp:ListItem Text="Thursday" Value="4"></asp:ListItem>
                  <asp:ListItem Text="Friday" Value="5"></asp:ListItem>
                  <asp:ListItem Text="Saturday" Value="6"></asp:ListItem>
                </asp:DropDownList>
                    </asp:TableCell></asp:TableRow><asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">Holiday Date:</asp:TableHeaderCell><asp:TableCell>
                    <asp:TextBox runat="server" ID="addHolidayBox" AutoPostBack="true" /><asp:CalendarExtender runat="server" ID="addHoliday" Animated="true" TargetControlID="addHolidayBox" /></asp:TableCell></asp:TableRow><asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">Start Time:</asp:TableHeaderCell><asp:TableCell>

                        <asp:DropDownList ID="addStartTimeHour" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addStartTimeMin" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addStartTimeAmPm" runat="server">
                            <asp:ListItem>AM</asp:ListItem>
                            <asp:ListItem>PM</asp:ListItem>
                        </asp:DropDownList>

                    </asp:TableCell></asp:TableRow><asp:TableRow>
                    <asp:TableHeaderCell HorizontalAlign="Left">End Time:</asp:TableHeaderCell><asp:TableCell>

                    <asp:DropDownList ID="addEndTimeHour" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addEndTimeMin" runat="server"></asp:DropDownList>
                        <asp:DropDownList ID="addEndTimeAmPm" runat="server">
                            <asp:ListItem>AM</asp:ListItem>
                            <asp:ListItem>PM</asp:ListItem>
                        </asp:DropDownList>

              </asp:TableCell></asp:TableRow><asp:TableRow>
              <asp:TableCell></asp:TableCell><asp:TableCell><asp:Button ID="btnAddHours" runat="server" Text="Add Hours" OnClick="btnAddHours_Click" /></asp:TableCell>  
      </asp:TableRow>

C#

        protected void btnAddHours_Click(object sender, EventArgs e)
    {
        hoursDataSource.InsertParameters["HolidayDate"].DefaultValue = addHoliday.SelectedDate.Value.ToString();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春夜浅 2024-11-17 15:06:03

您需要从 Textbox 获取值,而不是 CalendarExtender

它应该像......

hoursDataSource.InsertParameters["HolidayDate"].DefaultValue = addHolidayBox.Text;

You need to get the value from the Textbox instead CalendarExtender

It should be like...

hoursDataSource.InsertParameters["HolidayDate"].DefaultValue = addHolidayBox.Text;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文