Click here to Skip to main content
15,353,677 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Member 14193605 1-Apr-19 21:01pm
   
What if I want my calender to display only tuesdays on calender using if else statement in asp.net, how would I do that?

See the solution here:
how to get Day Name from calendar control in asp.net(c#)[^]

Calendar1.SelectedDate.DayOfWeek
   
v2
C#
Calendar1.SelectedDate.DayOfWeek
   
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[^]
   
v2
Comments
Kmurali Krishna 4-Dec-12 4:43am
   
Sorry guys I want to display the "date".
Mendor81 4-Dec-12 4:47am
   
?
Kmurali Krishna 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 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 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 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?
[no name] 12-Dec-12 23:42pm
   
label is inside the grid. While calendar selection index changed "label" name is not taking..
Pankaj Kumar Barnawal 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 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.
Simple one line way of converting a day number to a day name

string dayName = Enum.GetName(typeOf(DayOfWeek), Calendar1.SelectedDate.DayOfWeek);
   

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900