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();
}
You need to get the value from the Textbox
instead CalendarExtender
It should be like...
hoursDataSource.InsertParameters["HolidayDate"].DefaultValue = addHolidayBox.Text;
精彩评论