On Feb 26, 3:00 pm, "Zeba" <coolz...@gmail .comwrote:
Hi,
I have a page with a calendar and two datalist items - one containing
month values and the other, year values. Depending on the month/year
value chosen ( in text/string format ) I should be able to display
the correct month of the calendar.
I thought it would be possible to use the OnSelectedIndex Changed
attribute of the dropdown list to call a javascript function that sets
the month value of the calendar...Some thing like :
<asp:DropDownLi st ID="MonthList" runat="server" AutoPostBack="T rue"
DataSourceID="A uctionMonthData Source" OnSelectedIndex Changed=getcal( )
</asp:DropDownLis t>
But how do I get access to the SelectedDate tag from inside getcal() ?
And do I have to manually convert the text values of the month into
numeric values ?
Thanks !
<asp:DropDownLi st id="ddlMonth" style="Z-INDEX: 101; LEFT: 64px;
POSITION: absolute; TOP: 24px" runat="server"
AutoPostBack="T rue"></asp:DropDownLis t>
<asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 8px; POSITION:
absolute; TOP: 24px" runat="server"> Month</asp:Label>
<asp:DropDownLi st id="ddlYear" style="Z-INDEX: 102; LEFT: 200px;
POSITION: absolute; TOP: 24px" runat="server"
AutoPostBack="T rue"></asp:DropDownLis t>
<asp:Label id="Label2" style="Z-INDEX: 104; LEFT: 152px; POSITION:
absolute; TOP: 24px" runat="server"> Year</asp:Label>
<asp:Calendar id="Calendar1" style="Z-INDEX: 105; LEFT: 16px;
POSITION: absolute; TOP: 72px" runat="server"> </asp:Calendar>
VB.NET
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
' Put user code to initialize the page here
If Not Page.IsPostBack Then
'Populate month in the dropdownlist
Dim strMonth As String = ""
Dim i As Integer
For i = 1 To 12
If i.ToString().Le ngth < 2 Then
strMonth = "0" + i.ToString()
ddlMonth.Items. Add(New ListItem(strMon th, strMonth))
Else
ddlMonth.Items. Add(New ListItem(strMon th, strMonth))
End If
Next
ddlMonth.Items. FindByValue(Dat eTime.Now.ToStr ing("MM")).Sele cted =
True
'Populate year in the dropdownlist
Dim j As Integer
For j = 1900 To 2050
ddlYear.Items.A dd(New ListItem(j.ToSt ring(),
j.ToString()))
Next
ddlYear.Items.F indByText(DateT ime.Now.ToStrin g("yyyy")).Sele cted =
True
End If
End Sub 'Page_Load
Private Sub ddlMonth_Select edIndexChanged( ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
ddlMonth.Select edIndexChanged
SetCalendarDate ()
End Sub 'ddlMonth_Selec tedIndexChanged
Private Sub ddlYear_Selecte dIndexChanged(B yVal sender As
System.Object, ByVal e As System.EventArg s) Handles
ddlYear.Selecte dIndexChanged
SetCalendarDate ()
End Sub 'ddlYear_Select edIndexChanged
Sub SetCalendarDate ()
Dim dtNewDate As DateTime
dtNewDate =
DateTime.Parse( (Int16.Parse(dd lMonth.Selected Item.Text) & "/1/" &
Int16.Parse(ddl Year.SelectedIt em.Text)))
Calendar1.Today sDate = dtNewDate
End Sub 'SetCalendarDat e
C#
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
if (!Page.IsPostBa ck )
{
//Populate month in the dropdownlist
string strMonth="";
for(int i = 1 ;i<=12;i++)
{
if (i.ToString().L ength <2 )
{
strMonth ="0" + i.ToString ();
ddlMonth.Items. Add (new
ListItem(strMon th,strMonth )) ;
}
else
{
ddlMonth.Items. Add (new
ListItem(strMon th,strMonth )) ;
}
}
ddlMonth.Items. FindByValue ( DateTime.Now.To String
("MM")).Selecte d =true;
//Populate year in the dropdownlist
for(int j = 1900 ;j<=2050;j++)
{
ddlYear.Items.A dd (new ListItem(j.ToSt ring(),j.ToStri ng
() )) ;
}
ddlYear.Items.F indByText (DateTime.Now.T oString
("yyyy")).Selec ted =true;
}
}
private void ddlMonth_Select edIndexChanged( object sender,
System.EventArg s e)
{
SetCalendarDate ();
}
private void ddlYear_Selecte dIndexChanged(o bject sender,
System.EventArg s e)
{
SetCalendarDate ();
}
void SetCalendarDate ()
{
DateTime dtNewDate;
dtNewDate =DateTime.Parse
(Int16.Parse(dd lMonth.Selected Item.Text) + "/1/" +
Int16.Parse( ddlYear.Selecte dItem.Text));
Calendar1.Today sDate=dtNewDate ;
}