简体   繁体   中英

Can't Get my Calendar to display correctly in ASP.NET web form

I have two drop down list and a calendar control in my webform. When I click on my calendar values. It should select the right values and place the values in my dropdown list, but nothing is showing in my drop down lists after i selected them. The ID values are correctly named. The even handler is wired. I'm confused what's going on. Here is the code I'm using to link them together.

 protected void clnArrival_SelectionChanged(object sender, EventArgs e)
{
    ddlMonth.SelectedValue = clnArrival.SelectedDate.Month.ToString();
    ddlDay.SelectedValue = clnArrival.SelectedDate.Day.ToString();

}

here my aspx code

  <asp:Calendar ID="clnArrival" runat="server" Visible="true"       
  OnSelectionChanged="clnArrival_SelectionChanged">
         <TodayDayStyle BackColor="Blue" Font-Bold="True" ForeColor="White"  
         />
         <TitleStyle BackColor="Blue" Font-Bold="True" ForeColor="White" />
        <NextPrevStyle ForeColor="White" />
    </asp:Calendar>

Edit

This information was taking from an answer that should have been an edit

<asp:DropDownList ID="ddlMonth" runat="server" Height="18px" Width="150px">
 </asp:DropDownList>
    <asp:DropDownList ID="ddlDay" runat="server" Width="173px">
 </asp:DropDownList>
    <asp:DropDownList ID="ddlMonth" runat="server" Height="18px"   
     Width="150px">
        <asp:ListItem Value="1">January</asp:ListItem>
        <asp:ListItem Value="2">February</asp:ListItem>
        <asp:ListItem Value="3">March</asp:ListItem>
        <asp:ListItem Value="4">April</asp:ListItem>
        <asp:ListItem Value="5">May</asp:ListItem>
        <asp:ListItem Value="6">June</asp:ListItem>
        <asp:ListItem Value="7">July</asp:ListItem>
        <asp:ListItem Value="8">August</asp:ListItem>
        <asp:ListItem Value="9">September</asp:ListItem>
        <asp:ListItem Value="10">October</asp:ListItem>
        <asp:ListItem Value="11">November</asp:ListItem>
        <asp:ListItem Value="12">December</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList ID="ddlDay" runat="server" Width="173px">
        <asp:ListItem Value="1">1</asp:ListItem>
        <asp:ListItem Value="2">2</asp:ListItem>
        <asp:ListItem>3</asp:ListItem>
        <asp:ListItem>4</asp:ListItem>
        <asp:ListItem>5</asp:ListItem>
        <asp:ListItem>6</asp:ListItem>
        <asp:ListItem>7</asp:ListItem>
        <asp:ListItem>8</asp:ListItem>
        <asp:ListItem>9</asp:ListItem>
        <asp:ListItem>10</asp:ListItem>
        <asp:ListItem>11</asp:ListItem>
        <asp:ListItem>12</asp:ListItem>
        <asp:ListItem>13</asp:ListItem>
        <asp:ListItem>14</asp:ListItem>
        <asp:ListItem>15</asp:ListItem>
        <asp:ListItem>16</asp:ListItem>
        <asp:ListItem>17</asp:ListItem>
        <asp:ListItem>18</asp:ListItem>
        <asp:ListItem>19</asp:ListItem>
        <asp:ListItem>20</asp:ListItem>
        <asp:ListItem>21</asp:ListItem>
        <asp:ListItem>22</asp:ListItem>
        <asp:ListItem>23</asp:ListItem>
        <asp:ListItem>24</asp:ListItem>
        <asp:ListItem>25</asp:ListItem>
        <asp:ListItem>26</asp:ListItem>
        <asp:ListItem>27</asp:ListItem>
        <asp:ListItem>28</asp:ListItem>
        <asp:ListItem>29</asp:ListItem>
        <asp:ListItem>30</asp:ListItem>
        <asp:ListItem>31</asp:ListItem>
    </asp:DropDownList>

 protected void clnArrival_SelectionChanged(object sender, EventArgs e)
{
    ddlMonth.SelectedValue = clnArrival.SelectedDate.Month.ToString();
    ddlDay.SelectedValue = clnArrival.SelectedDate.Day.ToString();

}

This code should work, now the two droplists will display the proper month and date, just make sure your aspx value property for the droplists are correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM