473,624 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying calendar month according to Datalist choice

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 !

Feb 26 '07 #1
6 3264
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 ;

}

Feb 26 '07 #2
Thanks Alexey,
My basic idea itself was flawed i guess...Is it actually possible to
call a javascript function from a server control for such a purpose ?
Btw, why did you use "private" void ddlYear_Selecte dIndexChanged( ) ?
The .aspx page inherits from the .cs file right ? It gave me an error
that it was inaccessible due to protection level, so I changed it to
protected.
-Thanks !

Feb 27 '07 #3
On Feb 27, 11:05 am, "Zeba" <coolz...@gmail .comwrote:
Thanks Alexey,
My basic idea itself was flawed i guess...Is it actually possible to
call a javascript function from a server control for such a purpose ?
The OnSelectedIndex Changed event executes on the server, when page is
posted back to the server and that is the getcal() event cannot be on
the client side. The Calendar is also a server control and to set the
selected date you need to execute a code on the server side.

If you really need to avoid the postback, you should not use the
server controls (at least for calendar). Use a javascript calendar
instead...

Feb 27 '07 #4
Okayy...thanks. .! That makes things clear..
On Feb 27, 4:12 pm, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :
On Feb 27, 11:05 am, "Zeba" <coolz...@gmail .comwrote:
Thanks Alexey,
My basic idea itself was flawed i guess...Is it actually possible to
call a javascript function from a server control for such a purpose ?

The OnSelectedIndex Changed event executes on the server, when page is
posted back to the server and that is the getcal() event cannot be on
the client side. The Calendar is also a server control and to set the
selected date you need to execute a code on the server side.

If you really need to avoid the postback, you should not use the
server controls (at least for calendar). Use a javascript calendar
instead
Feb 27 '07 #5
On Feb 27, 12:26 pm, "Zeba" <coolz...@gmail .comwrote:
Okayy...thanks. .! That makes things clear..
Unfortunately I don't have any good example for this. You can google
for "javascript calendar asp.net" to look for most suitable code. It's
really depend on the need.

Feb 27 '07 #6
"Alexey Smirnov" <al************ @gmail.comwrote in message
news:11******** *************@h 3g2000cwc.googl egroups.com...
Unfortunately I don't have any good example for this. You can google
for "javascript calendar asp.net" to look for most suitable code. It's
really depend on the need.
I have one which is free to anyone who contacts me privately and asks for
it...
Feb 27 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1602
by: Hitit | last post by:
I found the script below in internet and I want it to create a page with links for each date changing according to date. For example: For August 10, the link in calendar page should point to: /cgi-bin/calendar_day.pl?userdir=calend&dept=boys&weekends=1&datestamp=20040 810 For August 11, the link in calendar page should point to: /cgi-bin/calendar_day.pl?userdir=calend&dept=boys&weekends=1&datestamp=20040 811
4
6689
by: Jason Chan | last post by:
How can I get the month and year a calendar control current displaying? My problem is I want to load a list of event to a calendar so that it display difference style if there a event for a day. My initial idea is load all events from database and store it in a DataTable. In the DayRender event, loop thr the DataTable and see if it equal to e.Day and alter the style if that is. However when the event table is large, it hurt...
11
1685
by: samuelberthelot | last post by:
Hi, I've got 3 input HTML (dropdown lists) on my page. One for selecting a Month, one for the day, one for the year. Very simple... My problem is that I'd like to update the Days one according to what month was selected (31,30 or 28 days). I should use a simple javascript to populate the input boxes, but I'm a bit new to javascript. Please can you help me ?
1
2225
by: ajmera.puneet | last post by:
If I have Calendar Control on Asp.net page and I have a table for Fiscal years on sql server then, How can I check the dates from table to Calendar Control,so that I can format the Calendar control cells according to my need. I want to change the color of Dates according to fiscal month. i.e. As Calendar control has dates for Current + next + Previous months, I need to change the color of dates of month which is comes under Fiscal...
19
3393
by: skyblue | last post by:
//can somebody help me with this please. i need to create a //calendar on the frame. i got the frame but the calendar is not //woking. import jpb.*; import java.awt.*; import java.awt.event.*; import java.util.*;
0
3323
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I would like to get the code for connecting the javascript to asp.net page... Please help me... The javascript code is as follows..
7
2292
by: William (Tamarside) | last post by:
Please, if you have the time and knowledge to help me I'd truly appreciate it! I need to build a calendar page that displays available/unavailable info from a DB and colour a cell according to that info, but somewhere I've gone completely off the rails! Basically it is a room availability page for an intranet and should simply colour a calendar cell red if the room is booked, or green if it isn't. Rooms are typically booked by lecturers...
38
3076
by: falconsx23 | last post by:
I am supposed to be makig a calendar program that will eventually allows the user to insert a number and the date will come up according to that number. But before we do that I need help from someone to give me small steps until we get it working correctly. This calendar program is supposed to have a number of if then statements. Here is my calendar program so far. Right now my calendar has a constructor identifying a month, day, and year. I...
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.