日历扩展器 SelectedDate Null
我有一个日历扩展程序“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要从
Textbox
获取值,而不是CalendarExtender
它应该像......
You need to get the value from the
Textbox
insteadCalendarExtender
It should be like...