DateTime Funk in DropDownList...

  • Thread starter Vagabond Software
  • Start date
V

Vagabond Software

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
 
V

Vagabond Software

Vagabond Software said:
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?

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
 

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

Top