Punkcrib
05-07-2008, 10:18 PM
I have two static DDL's (meaning they are not data bound, but rather have their items entered manually at design time). These DDL's correspond to Months and Years. The Month's DDL has Jan-Dec, with values of 1-12. The Year's DDL has 2000-2015, with values of 2000-2015.
This is my .aspx page's body code:
<form id="form1" runat="server">
<div style="text-align: center">
<asp:Label ID="Label1" runat="server" Text="Select a month and year to view: "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<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="DropDownList2" runat="server">
<asp:ListItem>2000</asp:ListItem>
<asp:ListItem>2001</asp:ListItem>
<asp:ListItem>2002</asp:ListItem>
<asp:ListItem>2003</asp:ListItem>
<asp:ListItem>2004</asp:ListItem>
<asp:ListItem>2005</asp:ListItem>
<asp:ListItem>2006</asp:ListItem>
<asp:ListItem>2007</asp:ListItem>
<asp:ListItem>2008</asp:ListItem>
<asp:ListItem>2009</asp:ListItem>
<asp:ListItem>2010</asp:ListItem>
<asp:ListItem>2011</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem>2013</asp:ListItem>
<asp:ListItem>2014</asp:ListItem>
<asp:ListItem>2015</asp:ListItem>
<asp:ListItem>2016</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Display" />
<br />
<br />
<%ReadData()%>
</div></form>
That is all that is coded on the page. The "ReadData()" method creates an event calendar that writes out a table w/ event info from a database. This is all working fine, except for the following:
In my ReadData() method I query the month and year. If no month or year was specified, I get the current month and year (using Month(Date.Now()), etc) and set those values in "intMonth" and "intYear". This works fine as it should. However, right after this I try to change the selected items of the DDL's to reflect intMonth and intYear by doing the following:
Me.DropDownList1.SelectedValue = intMonth
Me.DropDownList2.SelectedValue = intYear
However, when the page displays it always defaults to selecting the 1st items in each DDL. I even created a button on the page that when clicked will execute the two statements above and that works fine. But it is not working when the page loads like it should.
Any ideas? I'm stumped.
This is my .aspx page's body code:
<form id="form1" runat="server">
<div style="text-align: center">
<asp:Label ID="Label1" runat="server" Text="Select a month and year to view: "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<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="DropDownList2" runat="server">
<asp:ListItem>2000</asp:ListItem>
<asp:ListItem>2001</asp:ListItem>
<asp:ListItem>2002</asp:ListItem>
<asp:ListItem>2003</asp:ListItem>
<asp:ListItem>2004</asp:ListItem>
<asp:ListItem>2005</asp:ListItem>
<asp:ListItem>2006</asp:ListItem>
<asp:ListItem>2007</asp:ListItem>
<asp:ListItem>2008</asp:ListItem>
<asp:ListItem>2009</asp:ListItem>
<asp:ListItem>2010</asp:ListItem>
<asp:ListItem>2011</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem>2013</asp:ListItem>
<asp:ListItem>2014</asp:ListItem>
<asp:ListItem>2015</asp:ListItem>
<asp:ListItem>2016</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Display" />
<br />
<br />
<%ReadData()%>
</div></form>
That is all that is coded on the page. The "ReadData()" method creates an event calendar that writes out a table w/ event info from a database. This is all working fine, except for the following:
In my ReadData() method I query the month and year. If no month or year was specified, I get the current month and year (using Month(Date.Now()), etc) and set those values in "intMonth" and "intYear". This works fine as it should. However, right after this I try to change the selected items of the DDL's to reflect intMonth and intYear by doing the following:
Me.DropDownList1.SelectedValue = intMonth
Me.DropDownList2.SelectedValue = intYear
However, when the page displays it always defaults to selecting the 1st items in each DDL. I even created a button on the page that when clicked will execute the two statements above and that works fine. But it is not working when the page loads like it should.
Any ideas? I'm stumped.