我有一个日历扩展程序“addHoliday”,但每次我选择一个值并尝试在其后面的代码中检索该值为null。我不确定为什么会这样。
表
<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();
}
答案 0 :(得分:2)
您需要从Textbox
而不是CalendarExtender
应该是......
hoursDataSource.InsertParameters["HolidayDate"].DefaultValue = addHolidayBox.Text;