Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi All,
 
How to get the days name in a calendar control in asp.net(c#).
for example:
when i select the week in a calendar control it should display the selected days name. such as Sunday,Monday, etc.
 
In my grid there are 7 text boxes are there. I want to display day of the week selection. (I have changed calendar selection to week)
 

Thanks and Regards,
Murali.k
Posted 3-Dec-12 23:17pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

See the solution here:
how to get Day Name from calendar control in asp.net(c#)[^]
 
Calendar1.SelectedDate.DayOfWeek
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Calendar1.SelectedDate.DayOfWeek
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Make a switch case for each of the possible results of
Switch(Calendar1.SelectedDate.DayOfWeek)
{
Case "0": return "Sunday" break;
Case "1": return "Monday" break;
etc
.
.
.
. 
}

 
0-6 and return string result as " 0= Sunday - 6 = Saturday"
 
have a look:
 
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar(v=vs.80).aspx[^]
  Permalink  
v2
Comments
Kmurali Krishna at 4-Dec-12 4:43am
   
Sorry guys I want to display the "date".
Mendor81 at 4-Dec-12 4:47am
   
?
Kmurali Krishna at 4-Dec-12 5:07am
   
No need to display the "day" , I need to display the "date". Based on week selection date should be shown for every textbox (top of the every text box, I have added 7 labels for that).
Mendor81 at 4-Dec-12 5:18am
   
I still don't get it exactly what you need. or your not explaining yourself very well in the context or i'm definitely getting old and stupid....i hope it's the first option, anyway
have tried to look at the properties of Calendar date object?
Kmurali Krishna at 4-Dec-12 5:59am
   
See, IN my aspx page one calendar control is there. I have changed calander contrl to week selection (calendar properties, selection MOde: DayWeek).
Based on week selection i am data is retrieving the data. That's fine. What i need is while retrieving time i want to display the "date" in label.
 
Ex: I have select week from 2 to 8. I want to display like this format "2-12-2012" in one label.. And second label output like this "3-12-2012".
Mendor81 at 4-Dec-12 6:04am
   
So basically just have to call :
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
label1.Text = "Current date: " + System.DateTime.Now.ToLongDateString();
label2.Text ="Selected date: " + Calendar1.SelectedDate.ToLongDateString();
}
 
for each lable increment the next date?! shouldn't be that hard or?
Pankaj Kumar Barnawal at 26-Aug-13 7:23am
   
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
label1.Text = "Current date: " + System.DateTime.Now.ToLongDateString();
label2.Text ="Selected date: " + Calendar1.SelectedDate.ToLongDateString();
}
Kmurali Krishna at 4-Dec-12 6:08am
   
I just added 7 labels for top of the every text box. calendar selection it self it should display with output.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Simple one line way of converting a day number to a day name
 
string dayName = Enum.GetName(typeOf(DayOfWeek), Calendar1.SelectedDate.DayOfWeek);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 3 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100