retrieving the original value from a calendar control

B

bill yeager

I would like to place the currently selected date
(retrieved from the database) on a calendar control which
is embedded inside a datagrid. However, I can't find the
ID of the control to do so. During the "Edit" command of
the grid, I have the following code:
<code>
If e.CommandName = "Edit" Then
Dim myDatagridItem As DataGridItem
Dim lblStartDate As Label
Dim lblEndDate As Label
For Each myDatagridItem In
dgPositions.Items
lblStartDate =
myDatagridItem.Controls.Item(4).FindControl
("lblStartDate")
lblEndDate =
myDatagridItem.Controls.Item(5).FindControl("lblEndDate")
Next
End If
</code>

This code successfully retrieves the date. In edit mode,
I have the textbox turning into a calendar control (When
not in edit mode, it's simply a textbox dispolaying the
date). When I go into edit mode, the selected date goes
away. I want to take the date from the code above, and
use it to set the calendar.selecteddate property so the
user can see the present date selected in the calendar
control.

The following code only works during the OnupdateCommand
and not during the "Edit" command of the grid:
<code>
Dim calStartDate As WebControls.Calendar = DirectCast
(e.Item.FindControl("calStartDate"), WebControls.Calendar)
Dim calEndDate As WebControls.Calendar =
DirectCast(e.Item.FindControl("calEndDate"),
WebControls.Calendar)
</code>

How can I properly set the "original" date to the
calendar control during the edit process?

Below, is what is in the HTML portion of my aspx page:
<code>
<asp:TemplateColumn HeaderText="StartDate">

<ItemTemplate>

<asp:Label id=lblStartDate runat="server" Text='<%
# DataBinder.Eval
(Container, "DataItem.StartDate", "{0:d}") %>'>

</asp:Label>

</ItemTemplate>

<EditItemTemplate>

<asp:Calendar id="calStartDate" Runat="server">

<TodayDayStyle Font-Size="XX-
Small"></TodayDayStyle>

<SelectorStyle Font-Size="XX-
Small"></SelectorStyle>

<DayStyle Font-Size="XX-Small"></DayStyle>

<NextPrevStyle Font-Size="XX-
Small"></NextPrevStyle>

<DayHeaderStyle Font-Size="XX-
Small"></DayHeaderStyle>

<SelectedDayStyle Font-Size="XX-
Small"></SelectedDayStyle>

<TitleStyle Font-Size="XX-Small"></TitleStyle>

<WeekendDayStyle Font-Size="XX-
Small"></WeekendDayStyle>

<OtherMonthDayStyle Font-Size="XX-
Small"></OtherMonthDayStyle>

</asp:Calendar>

</EditItemTemplate>

</asp:TemplateColumn>
</code>
 
G

Guest

check out the ItemDataBound event and also e.Item.ItemType Property. Move the code to reference the Calendar Control here

Regards

Trevor Benedict R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top