Populating multiple dropdownlists from a single database field.

Last post 09-08-2006 9:33 AM by Swackhammer1. 6 replies.

Sort Posts:

  • Populating multiple dropdownlists from a single database field.

    09-07-2006, 3:22 PM

    Hi,

    For this project I'm using .Net 1.1 and VB. I'm trying to create ddl's for the 'date of birth'. That is, one ddl for month, one for day, and one for year. I want to combine those values and update a single 'dob' field of the table (currently in MS Access). Also, I need to be able to retrieve an existing dob and have each ddl show the appropriate value.

    For example, if I login to the site and select 'January', '10', '1970' from the individual ddls and click submit, the date should be stored as '01/10/1970' in the 'dob' field. When I come back to the site at another time, the ddls should show the correct date that was already selected, ie, 'January', '10', '1970'.

    I can submit individual ddl values to the table (that's not what I want to do anyways), but I have no idea how to do the rest. 

    Any help would be appreciated.

    Thanks. 

  • Re: Populating multiple dropdownlists from a single database field.

    09-07-2006, 11:29 PM

    Hi~ You can plus another submit button, in its Click: 

    DateTime dob = new DateTime();
    if (DateTime.TryParse(string.Format("{0} {1}, {2}", "January", "10", "2006"), out dob))    // Change "January" to someDDL.SelectedValue etc.
    {
        // Blah blah blah, write to DB
    }
     
    你好! Just FYI o_O
  • Re: Populating multiple dropdownlists from a single database field.

    09-07-2006, 11:37 PM

    Hi,

    I'm not quite sure what you mean by 'plus another submit button'. I'm using stored procedures and cmd.Parameters like so:

     

    cmd.Parameters.Add("d1DOB", OleDbType.DBDate, 50).Value = dependentDOB01.Text

      

     would the implementation change in this case? Also, the code you gave would submit the data to the db, but what would happen when I come back to the page and need the ddls to show the correct values?

    Thanks. 

  • Re: Populating multiple dropdownlists from a single database field.

    09-08-2006, 12:19 AM
    • Loading...
    • mokeefe
    • Joined on 08-20-2006, 5:15 AM
    • Canberra Australia
    • Posts 2,096
     

    You don't want to assign the text as per your example! Assign a date to the Paramater of type date. Also review the Parameter size, I am using default size for Type DateTime. The DB Field must of Type Date

    'New System.DateTime(Year as integer, Month as integer, days as integer)

    Dim DOBDate As Date = New System.DateTime(1970, 1, 15)

    Dim DOBparam As New SqlParameter("@Dob", Data.SqlDbType.DateTime)

    DOBparam.Value = DOBDate

    If you are using a Dropdownlist for the Months you can use the value field for the Month as Integer. You also use the parsing options but you may find this more difficult.

    On data retrieval you just create another datetime variable and assign the retrieved value. then use the available properties to print or select the date in a calendar.

     

     

     

    Rgds,
    Martin.

    For the benefit of all users please mark any post answers as appropriate.
  • Re: Populating multiple dropdownlists from a single database field.

    09-08-2006, 1:06 AM

    I think I get the submission part, but I still don't understand the retrieval.

    If I just retrieve the data from the 'dob' field, it will be a DateTime in the form mm/dd/yyyy. How would I send the 'mm' part to the month ddl, the 'dd' part to the day ddl and the 'yyyy' part to the year ddl?

     

    Thanks. 

  • Re: Populating multiple dropdownlists from a single database field.

    09-08-2006, 1:18 AM
    Hi~ You just want the parts? then dob.Month, dob.Day & dob.Year will do, they are all of type int
    你好! Just FYI o_O
  • Re: Populating multiple dropdownlists from a single database field.

    09-08-2006, 9:33 AM

    Oh. Excellent. I'll try that out.

    Thanks. 

Page 1 of 1 (7 items)
Microsoft Communities
Page view counter