INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Display days split in half

Display days split in half

(OP)
Hi

I am writing an application that incorporates the standard ASP.Net calendar and I wanted to know if it is possible to display a day split in 2?

i.e. If a statff member is on holiday today but only on a half day this morning, I want to show this morning as the specified colour and this afternoon as my standard defined calendar calendar!

If this is possible can someone please point me in the right direction?

Many thanks

Steve

RE: Display days split in half

I never tried it but what you should do is look at the page "view source" once it is rendered. I would assume it is a table cell. However I don't think you would be able to "split" it.
What you might have to do is divide each calender cell in 2 by adding 2 table cells or divs to each one. Then you can color those objects instead of the calendar cell itself.

RE: Display days split in half

(OP)
Thanks again for the advice Jbenson001

I have another issue with this calendar too that maybe you wouldn't mind assisting with?

I want to change colour and disable days where a person may not be working! I've validated the numbers within my code as being correct but for some reason, it colours all the days the same! The code is below....what am I doing wrong?

If (e.Day.Date.DayOfWeek + 1) <> CurrentDay Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If

Best reagrds

Steve

RE: Display days split in half

Did the isselectable = false work? is it just the color that is the issue?
if it is just the color, it could be that you just can't really see it on your monitor. Just try a very sever color like Aqua just for testing.

RE: Display days split in half

(OP)
It is setting all days to the colour (no problem with display) and disabling all of them....it just doesn't make sense! FYI, the code is within the DayRender and I've displayed the whole subroutine in case it's something else!

Thanks for your help.

Private Sub Calendar1_DayRender(sender As Object, e As DayRenderEventArgs) Handles Calendar1.DayRender

Dim DayLoop As Integer = 0
Dim CurrentDay As Integer = 0

For DayLoop = 1 To 7
Select Case DayLoop
Case 1
If Session("StylistDay1") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 2
If Session("StylistDay2") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 3
If Session("StylistDay3") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 4
If Session("StylistDay4") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 5
If Session("StylistDay5") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 6
If Session("StylistDay6") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 7
If Session("StylistDay7") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
End Select

If (e.Day.Date.DayOfWeek + 1) <> CurrentDay Then
' 'MsgBox((e.Day.Date.DayOfWeek + 1) & " " & CurrentDay)
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If

Next DayLoop

If e.Day.Date.DayOfWeek + 1 = Session("ClosedDay") Then
e.Cell.BackColor = System.Drawing.Color.Firebrick
e.Day.IsSelectable = False
End If

Dim nextDate As DateTime

If Not CType(Session("PublicHolidays"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("PublicHolidays"), DataSet).Tables(0).Rows
nextDate = CType(dr("BankHoliday"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.CornflowerBlue
End If
Next
End If

If Not CType(Session("StylistHolidays"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHolidays"), DataSet).Tables(0).Rows
nextDate = CType(dr("HolidayDate"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.Red
'e.Cell.Text = "SH"
End If
Next
End If

If e.Day.Date = Today Then
e.Cell.BackColor = System.Drawing.Color.Green
End If

End Sub

RE: Display days split in half

you have e.day.date.dayofweek + 1 which technically is incorrect(but does not throw and error). dayofweek returns the day name like "Sunday", "Monday" ..etc so I think you have a flaw there
And you really need to step through each line and be sure you are getting values you expect from session etc.

RE: Display days split in half

(OP)
I've just debugged the value of e.day.date.dayofweek and it returns a numeric between 0 and 6 not a day name as you suggest....this was the reasoning behind performing arithmetic on it to match my days.

I'll take a look at the links and see if that throws any further light.

Thanks again

RE: Display days split in half

they dayofweek is showing you a numeric value because you are adding 1 to it. the property itself returns a string value of"Sunday".. etc

RE: Display days split in half

remove all code in your dayrender event and put this
Response.Write(e.Day.Date.DayOfWeek.ToString() + "<br />")

then do
Response.Write(e.Day.Date.DayOfWeek + 1)

You will see what I mean

RE: Display days split in half

(OP)
Hi JBension001

I've totally changed the way I coded this, removing all of the arithmetic...my original routines that were writing the data were writing it incorrectly!

I have a table called StylistHours which holds data relating to days worked. I want my calendar to change the colour and not allow selection if the day does not match any of the day records within this table.

The data from the table is built into a dataset and the following code runs:

Dim NextDay As Integer

If Not CType(Session("StylistHours"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHours"), DataSet).Tables(0).Rows
NextDay = CType(dr("Day"), Integer)
If NextDay = e.Day.Date.DayOfWeek.ToString Then
Else
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Next
End If

This code changes every cell to LightSalmon! I have put a display into the 'If NextDay' and it is finding matches correctly so can you see why it would be setting all the days?

Thanks

Steve

RE: Display days split in half

(OP)
Apolofies for the name mispell JBenson001.....just to advise that one of my coded lines is incorrect If NextDay = e.Day.Date.DayOfWeek.ToString, ignore the .tostring

RE: Display days split in half

(OP)
So how do I actually compare it then? I've tried the following now and that doesn't work either!!

Dim NextDay As Integer

If Not CType(Session("StylistHours"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHours"), DataSet).Tables(0).Rows
NextDay = CType(dr("Day"), Integer)

If NextDay = Int(e.Day.Date.DayOfWeek) Then
Else
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Next
End If

Thanks again

Steve

RE: Display days split in half

(OP)
I've also tried this too....this doesn't work either!

Dim NextDay As Integer
Dim NextDayName As String = String.Empty

If Not CType(Session("StylistHours"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHours"), DataSet).Tables(0).Rows
NextDay = CType(dr("Day"), Integer)
Select Case NextDay
Case 1
NextDayName = "Monday"
Case 2
NextDayName = "Tuesday"
Case 3
NextDayName = "Wednesday"
Case 4
NextDayName = "Thursday"
Case 5
NextDayName = "Friday"
Case 6
NextDayName = "Saturday"
Case 7
NextDayName = "Sunday"
End Select

If NextDayName = e.Day.Date.DayOfWeek.ToString Then
Else
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Next
End If

RE: Display days split in half

I don't know your data
what columns/values are in the dataset?
What do they represent? What datatype(s) are they?

The debugger is great. You can stop it on your case and inspect your data elements to be sure you have what you expect.
You can then also check the properties of the cell object and see what properties/methods are available to you.

I was playing with it yesterday and found lots of properties on the cell object I didn't know existed and could possible use.

RE: Display days split in half

(OP)
Within the StylistHours table is a column called 'Day' which is an integer and stores values from 1 to 7. These represent the days that a stylist is available to work.

I'm trying to change the calendar colour for days where the stylist does not work and also to make those days non-selectable.

RE: Display days split in half

This is a quick example. My logic is probably way off from what you want but hopefully it will help.

CODE

dim dt as datatable = DirectCast(Session("StylistHours"), DataSet).Tables(0)
For Each dr As DataRow In dt.rows
  Select Case dr("Day")
     Case "1"
        if e.Day.dayNumberText = "1" then

        end if 
     Case "2"

     Case "3" 


        ...etc
  End Select

end for 

RE: Display days split in half

(OP)
Right, I think we are making progress! Your code actually relates to the day number within the actual date as opposed to the day number of the week.

I have changed the code to the following and the result is as attached, however, it's the wrong way round! The days that are salmon coloured shouldn't be and the days that aren't, should be!

Dim dt As DataTable = DirectCast(Session("StylistHours"), DataSet).Tables(0)
For Each dr As DataRow In dt.Rows
Select Case dr("Day")
Case "1"
If e.Day.Date.DayOfWeek.ToString = "Monday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "2"
If e.Day.Date.DayOfWeek.ToString = "Tuesday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "3"
If e.Day.Date.DayOfWeek.ToString = "Wednesday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "4"
If e.Day.Date.DayOfWeek.ToString = "Thursday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "5"
If e.Day.Date.DayOfWeek.ToString = "Friday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "6"
If e.Day.Date.DayOfWeek.ToString = "Saturday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "7"
If e.Day.Date.DayOfWeek.ToString = "Sunday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
End Select
Next

RE: Display days split in half

(OP)
I think I may have come up with the solution....the last set of code I supplied i believe is right!! It's the criteria for building the dataset that is wrong! The data relates to Stylists actual working days, which need to be selectable, so I need to change that to store the records that aren't there, ie If they work Monday, Tuesday and Thursday, my dataset needs to contain the remaining days....watch this space!

RE: Display days split in half

Cool, let me know how it goes

RE: Display days split in half

(OP)
Good Morning!

Massive progress, however still a slight issue!

I moved away from the dataset and built an array containing 0/1 depending on whether its a workday, non-working days being = 0. This works perfectly on the first display of the calendar. If I move forward to the next month, all off the dates change colour! The code is below and the before and after images attached....let me know what you think?

Dim Day_Loop As Integer = 0

For Day_Loop = 1 To 7
If Days(Day_Loop) = 0 Then
Select Case Day_Loop
Case "1"
If e.Day.Date.DayOfWeek.ToString = "Monday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "2"
If e.Day.Date.DayOfWeek.ToString = "Tuesday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "3"
If e.Day.Date.DayOfWeek.ToString = "Wednesday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "4"
If e.Day.Date.DayOfWeek.ToString = "Thursday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "5"
If e.Day.Date.DayOfWeek.ToString = "Friday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "6"
If e.Day.Date.DayOfWeek.ToString = "Saturday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "7"
If e.Day.Date.DayOfWeek.ToString = "Sunday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
End Select
End If
Next

RE: Display days split in half

What event are you building your array? Remember, the calendar causes a postback on change of month or day selection. did you wrap the build of the array in a

CODE

if not page.ispostback thn
'build array
end if 

RE: Display days split in half

(OP)
The array is only built the one time, on a selectedindexchanged on a dropdownlist

RE: Display days split in half

You will have to debug. do you still have access to the array after postback? etc

RE: Display days split in half

(OP)
We finally got there!! I always forget about postback....my first web pages project!! I recoded it so that it stored as a session variable!!

Many thanks for your extensive assistance (Speak again, I'm sure!)

RE: Display days split in half

Glad to help.
Remember that on a post back in most cases you don't want/need to access the db and rebuild data. Just wrap you code in:

CODE

If NOT page.IsPostback
Me.GetData
End if 

CODE

i usually do this in the page_load or page_init and put my data access code in a separate function or sub
private sub GetData()
get data...
bind to control...
end sub 


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close