|
-
Sep 6th, 2005, 04:14 AM
#1
Thread Starter
Addicted Member
Custom Calendar Which Can Return Null dates
Hiya,
I hope someone can help me with this.
From what i can see there doesn't seem to be a way to show a Calendar control with a null date.
In my app have a Datalist where there are a number of labels. 2 of these labels are for Start_Date and End_Date. It is possible that there is not a date shown in these labels if there is no date in the database. Upon selecting the edit button on a given record i go to the edititemtemplate section where most of the labels are changed to text boxes. The two date labels however are change for the calendar control. If i want to enter a null date there seems to be no possible way to do this (Although i probably just haven't found it yet).
Firstly, is there a way i can select a null date?
if not could some one help me with some advice on how to customise the calender control, possibly to include a check box that can be selected for null.
I haven't looked into customizing server controls yet and think this would be a good example to do this with.
All help is greatly recieved and appreciated.
Thanks in advance.
-
Sep 6th, 2005, 08:44 AM
#2
Thread Starter
Addicted Member
Re: Custom Calendar Which Can Return Null dates
Ok.
Just an update. I think from what i've read elsewhere i can create a composite control with both a calendar control and a check box control. i have the following code which as far as i can make out is correct but isn't working correctly:
Code:
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System
Namespace myCalendar
Public Class nullCalendar
Inherits System.Web.UI.WebControls.Calendar : Implements INamingContainer
Protected Overrides Sub CreateChildControls()
Dim cal As New Calendar
Dim cb As New CheckBox
Me.Controls.Add(cal)
Me.Controls.Add(New LiteralControl("<P>"))
Me.Controls.Add(cb)
End Sub
End Class
End Namespace
when i add the dll that is created to my app and then drag the control on to the page i get an error stating:
'myCalendar.myCalendar.nullCalendar' does not allow child controls.
Not to sure why this is happening as i thought overriding the createchildcontrols would stop this error.
Does anyone have an idea as to what i may have done wrong.
Cheers
-
Sep 7th, 2005, 07:09 AM
#3
Thread Starter
Addicted Member
Re: Custom Calendar Which Can Return Null dates
OK,
Solved this problem myself as well.
i was inheriting a "calendar" as apposed to just "control".
This part's now working and the composite control is working basically with the following code.
Code:
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System
Namespace myCalendar
Public Class nullCalendar
Inherits Control
Implements INamingContainer
Dim cal As New Calendar
Dim cb As New CheckBox
Public Property dateVal() As Object
Get
Select Case cb.Checked
Case True : Return DBNull.Value
Case False
If cal.SelectedDate = "" Then
cal.SelectedDate = Today
End If
Return cal.SelectedDate
End Select
End Get
Set(ByVal Value As Object)
If Value = "" Then
cb.Checked = True
cal.Enabled = False
Else
cb.Checked = False
cal.SelectedDate = Value
cal.VisibleDate = Value
End If
End Set
End Property
Sub cbChange(ByVal s As Object, ByVal e As EventArgs)
Select Case cb.Checked
Case True : cal.Enabled = False
Case False : cal.Enabled = True
End Select
End Sub
Protected Overrides Sub CreateChildControls()
Me.Controls.Add(cal)
Me.Controls.Add(New LiteralControl("<P>"))
Me.Controls.Add(cb)
cb.Text = "No Date Required"
cb.AutoPostBack = True
AddHandler cb.CheckedChanged, AddressOf cbChange
End Sub
End Class
End Namespace
I still have one more problem with the custom control. When i have two on the same page and a post back occurs from one control, the other loses its settings.
Can anyone help with how to keep the settings after postbacks.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|