SelectedDate property of calendar control

wsyeager

Centurion
Joined
Apr 10, 2003
Messages
140
Location
Weston, FL
I'm having trouble trying to set a value to this property. When the calendar control is displayed alone on a webform (NOT inside a datagrid), the property is READ and WRITE. I am able to set a value to it.

When the control is placed inside a datagrid column, I can't set the value of the SelectedDate property. It informs me that it's READONLY.

Below, is the HTML on the ASPX page of what is happening:
<code>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="NCVACEMT.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 504px; POSITION: absolute; TOP: 216px" runat="server" Height="416px" Width="712px" DataSource="<%# DsMeeting1 %>" DataKeyField="MeetingID" DataMember="Meeting" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="MeetingDate">
<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.MeetingDate") %>'>
</asp:Label>
<asp:Calendar id="Calendar1" runat="server"></asp:Calendar>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.MeetingDate") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<asp:Calendar id="Calendar2" style="Z-INDEX: 102; LEFT: 104px; POSITION: absolute; TOP: 240px"
runat="server"></asp:Calendar>
</form>
</body>
</HTML>
</code>

Here is the code-behind:
<code>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Calendar2.SelectedDate = "01/01/04"


End Sub

Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand

Dim myDatagridItem As DataGridItem
Dim c As Calendar

For Each myDatagridItem In DataGrid1.Items
c = myDatagridItem.FindControl("Calendar1")
'c = DirectCast(myDatagridItem.FindControl("Calendar1"), Calendar)
c.SelectedDate = "01/01/04"
Next

'and i also tried this:
c = DirectCast(e.Item.FindControl("Calendar1"), Calendar)
c.SelectedDate = "01/01/04"

End Sub
</code>

In the page load event, the date gets set fine, but not in the above event. I even tried placing the above code inside the page load event as well (just setting calendar1.selecteddate to a date, but still didn't work).

Can someone please inform me how I can set the SELECTEDDATE property. The reason being, is that once the data is loaded into a dataset, I want to set the value of the date on the calendar control to the SelectedDate.
 
Back
Top