Date Selection In a Form

Results 1 to 2 of 2

Thread: Date Selection In a Form

  1. #1
    Join Date
    Dec 1969

    Default Date Selection In a Form

    Can anyone tell me how to split a date value retrieved from a database and put the day, month, and year in separate drop down boxes? When the form is submitted I want the day, month and year values to recombine to save to the database. Here is an exract of the script i have that creates a single drop down for the date (obviously this would be too long a list to use in an application:<BR><BR>
    <BR>Sub Page_Load(Sender As Object, E As EventArgs)<BR>.<BR>.<BR>.<BR>For ArchiveDateIndex=0 To ArchiveDateDropDown.Items.Count -1<BR>			If ArchiveDateDropDown.Items(ArchiveDateIndex).Value = Row.Item("ArchiveDate") Then<BR>				ArchiveDateDropDown.Items(ArchiveDateIndex).Selected = True<BR>			End If<BR>		Next<BR><BR>.<BR>.<BR>End Sub<BR><BR>Sub Submit_Click(Sender As Object, E As EventArgs)<BR>.<BR>.<BR>Row.Item("ArchiveDate") = ArchiveDateDropDown.SelectedItem.Value<BR>	<BR>	Adapter.Update(MyDS, "MyTable")<BR>.<BR>.<BR>End Sub<BR>
    <BR><BR><BR>And in the html:<BR><BR>&#060;asp:dropdownlist id="ArchiveDateDropDown" runat="server" &#062;<BR> <BR> &#060;asp:listitem Value="01/06/04"&#062;01/06/04&#060;/asp:listitem&#062;<BR> &#060;asp:listitem Value="02/06/04"&#062;02/06/04&#060;/asp:listitem&#062;<BR> &#060;asp:listitem Value="03/06/04"&#062;03/06/04&#060;/asp:listitem&#062;<BR> &#060;/asp:dropdownlist&#062;

  2. #2
    Join Date
    Dec 1969

    Default so you want three different drops?

    then say you get a Data from the DB in a DataReader and the column name is "DateSent" (for sake of simplicity i am going to assume that is never coming out of the DB as NULL), and your GUI has three dropdowns named "drpMonth", "drpDay", "drpYear" then<BR><BR>[code language="VB.NET"]Dim CurrentDate As DateTime = ThisReader.Item("DateSent")<BR>Dim LI As ListItem<BR>LI = drpMonth.Items.FindByValue(CStr(CurrentDate.Month) )<BR>If Not IsNothing(LI) then LI.Selected = True<BR>LI = drpDay.Items.FindByValue(CStr(CurrentDate.Day))<BR >If Not IsNothing(LI) then LI.Selected = True<BR>LI = drpYear.Items.FindByValue(CStr(CurrentDate.Year))< BR>If Not IsNothing(LI) then LI.Selected = True[/code]<BR><BR>hopefully that works for ya... i am typically a little incoherant before coffee in the monrning :)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts