Groups | Blog | Home
all groups > asp.net > may 2006 >

asp.net : DateTime Funk in DropDownList...


Vagabond Software
5/31/2006 11:49:43 PM
I'm using a DropDownList in an EditItemTemplate column. This DropDownList
will only ever have two dates in it; Now and the default DateTime value
(1/1/1900 12:00:00 AM).

Somewhere, somehow, the DropDownList is interpreting the default DateTime
value as a string value "1/1/0001 12:00:00 AM". DateTime.Parse in turn
converts that string value to #12:00:00 AM# with no date values. What am I
doing wrong here?

Here is some relevant code (I'm new to ASP.NET, so I welcome
criticism/correction on any part of this):

<asp:TemplateColumn HeaderText="Check-In Date">
<ItemStyle horizontalalign="Left" wrap="False"></ItemStyle>
<ItemTemplate>
<%#Databinder.Eval(Container.DataItem, "checkin_DT")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlCheckinDT" Runat="server"
CssClass="ddl100"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

ASP web stuff...

<asp:TemplateColumn HeaderText="Check-In Date">
<ItemStyle horizontalalign="Left" wrap="False"></ItemStyle>
<ItemTemplate>
<%#Databinder.Eval(Container.DataItem, "checkin_DT")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlCheckinDT" Runat="server"
CssClass="ddl100"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

EditItem Method in Codebehind...

Private Sub EditAttendeeRecord(ByVal index As Integer)

Dim defaultDate As DateTime

ddlCheckin =
DirectCast(dgAttendees.Items(index).FindControl(CTL_DDLCHECKINDT),
WebControls.DropDownList)
ddlCheckin.Items.Add(regRow.CheckIn_DT.ToString)
If regRow.CheckIn_DT.Equals(defaultDate) Then
ddlCheckin.Items.Add(DateTime.Now.ToString)
Else
ddlCheckin.Items.Add(defaultDate.ToString)
End If

End Sub

SaveItem Method in Codebehind...

Private Sub SaveAttendeeRecord(ByVal index As Integer)

regRow.CheckIn_DT =
DateTime.Parse(DirectCast(dgAttendees.Items(index).FindControl(CTL_DDLCHECKINDT),
WebControls.DropDownList).SelectedValue)

End Sub

The value of the CheckIn_DT property on my regRow data object is #12:00:00
AM# at this point in the code.

Regards,

carl

Vagabond Software
6/1/2006 5:57:15 AM
[quoted text, click to view]

Nevermind. I now remember why I should never code tired.

My data object was skipping the property in the update statement because it
was default value.

carl

AddThis Social Bookmark Button