DateTime in dropdown

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff User

    DateTime in dropdown

    Hi all

    The date values in my dropdown list appear as mm/dd/yyyy
    Specifically, the day always contains 2 digits.
    I need to set the selected index of the dropdown to the date that
    equals another date value that does not use 2 digits for the day, if
    the day is less that 10.
    example
    ddlBeginDate.Se lectedIndex =
    ddlBeginDate.It ems.IndexOf(ddl BeginDate.Items .FindByText(som eClass.BeginDat e.ToShortDateSt ring()));

    does not work when the list contains 10/07/2006
    and the value returned by someClass.Begin Date.ToShortDat eString() is
    10/7/2006

    How can I set this list value to be the date returned frm the class?

    Thanks
    Jeff
  • justin creasy

    #2
    Re: DateTime in dropdown

    Jeff,

    Does the value have to be stored in SelectedIndex or could you
    subscribe to the SelectedIndexCh anged event, and when you catch the
    event do the processing needed to remove the extra digit and place it
    into another variable.

    Jeff User wrote:
    Hi all
    >
    The date values in my dropdown list appear as mm/dd/yyyy
    Specifically, the day always contains 2 digits.
    I need to set the selected index of the dropdown to the date that
    equals another date value that does not use 2 digits for the day, if
    the day is less that 10.
    example
    ddlBeginDate.Se lectedIndex =
    ddlBeginDate.It ems.IndexOf(ddl BeginDate.Items .FindByText(som eClass.BeginDat e.ToShortDateSt ring()));
    >
    does not work when the list contains 10/07/2006
    and the value returned by someClass.Begin Date.ToShortDat eString() is
    10/7/2006
    >
    How can I set this list value to be the date returned frm the class?
    >
    Thanks
    Jeff

    Comment

    • Jeff User

      #3
      Re: DateTime in dropdown


      The dropdown is a list of dates. I have to find the index of the date
      desired to set it as the selected item in the list. The desired value
      being the date with only the 1 digit for the day, the list items being
      the dates with 2 digits. I spose I can add the zero to the 1 digit day
      to make it match the dropdown date format.
      I was wondering if there was some way to use formating to get one to
      look like the other.

      Thanks

      On 26 Oct 2006 10:31:09 -0700, "justin creasy"
      <justin.creasy@ gmail.comwrote:
      >Jeff,
      >
      >Does the value have to be stored in SelectedIndex or could you
      >subscribe to the SelectedIndexCh anged event, and when you catch the
      >event do the processing needed to remove the extra digit and place it
      >into another variable.
      >
      >Jeff User wrote:
      >Hi all
      >>
      >The date values in my dropdown list appear as mm/dd/yyyy
      >Specifically , the day always contains 2 digits.
      >I need to set the selected index of the dropdown to the date that
      >equals another date value that does not use 2 digits for the day, if
      >the day is less that 10.
      >example
      >ddlBeginDate.S electedIndex =
      >ddlBeginDate.I tems.IndexOf(dd lBeginDate.Item s.FindByText(so meClass.BeginDa te.ToShortDateS tring()));
      >>
      >does not work when the list contains 10/07/2006
      >and the value returned by someClass.Begin Date.ToShortDat eString() is
      >10/7/2006
      >>
      >How can I set this list value to be the date returned frm the class?
      >>
      >Thanks
      >Jeff

      Comment

      • chanmm

        #4
        Re: DateTime in dropdown

        Have you play with the Regional and Language Options in Control Panel and
        see what is the effect?

        chanmm

        "Jeff User" <jeff31162@hotm ail.comwrote in message
        news:fd22k2djn8 r5oj71o7pic7gjq 5ddanrl4q@4ax.c om...
        >
        The dropdown is a list of dates. I have to find the index of the date
        desired to set it as the selected item in the list. The desired value
        being the date with only the 1 digit for the day, the list items being
        the dates with 2 digits. I spose I can add the zero to the 1 digit day
        to make it match the dropdown date format.
        I was wondering if there was some way to use formating to get one to
        look like the other.
        >
        Thanks
        >
        On 26 Oct 2006 10:31:09 -0700, "justin creasy"
        <justin.creasy@ gmail.comwrote:
        >
        >>Jeff,
        >>
        >>Does the value have to be stored in SelectedIndex or could you
        >>subscribe to the SelectedIndexCh anged event, and when you catch the
        >>event do the processing needed to remove the extra digit and place it
        >>into another variable.
        >>
        >>Jeff User wrote:
        >>Hi all
        >>>
        >>The date values in my dropdown list appear as mm/dd/yyyy
        >>Specificall y, the day always contains 2 digits.
        >>I need to set the selected index of the dropdown to the date that
        >>equals another date value that does not use 2 digits for the day, if
        >>the day is less that 10.
        >>example
        >>ddlBeginDate. SelectedIndex =
        >>ddlBeginDate. Items.IndexOf(d dlBeginDate.Ite ms.FindByText(s omeClass.BeginD ate.ToShortDate String()));
        >>>
        >>does not work when the list contains 10/07/2006
        >>and the value returned by someClass.Begin Date.ToShortDat eString() is
        >>10/7/2006
        >>>
        >>How can I set this list value to be the date returned frm the class?
        >>>
        >>Thanks
        >>Jeff
        >

        Comment

        • justin creasy

          #5
          Re: DateTime in dropdown

          Well, if you are using the DateTime object in .NET you can cast the
          same object into many forms which would allow you to check for
          equality. Read about the different methods in the DateTime object here

          Represents an instant in time, typically expressed as a date and time of day.


          Hope that helps.

          Jeff User wrote:
          The dropdown is a list of dates. I have to find the index of the date
          desired to set it as the selected item in the list. The desired value
          being the date with only the 1 digit for the day, the list items being
          the dates with 2 digits. I spose I can add the zero to the 1 digit day
          to make it match the dropdown date format.
          I was wondering if there was some way to use formating to get one to
          look like the other.
          >
          Thanks
          >
          On 26 Oct 2006 10:31:09 -0700, "justin creasy"
          <justin.creasy@ gmail.comwrote:
          >
          Jeff,

          Does the value have to be stored in SelectedIndex or could you
          subscribe to the SelectedIndexCh anged event, and when you catch the
          event do the processing needed to remove the extra digit and place it
          into another variable.

          Jeff User wrote:
          Hi all
          >
          The date values in my dropdown list appear as mm/dd/yyyy
          Specifically, the day always contains 2 digits.
          I need to set the selected index of the dropdown to the date that
          equals another date value that does not use 2 digits for the day, if
          the day is less that 10.
          example
          ddlBeginDate.Se lectedIndex =
          ddlBeginDate.It ems.IndexOf(ddl BeginDate.Items .FindByText(som eClass.BeginDat e.ToShortDateSt ring()));
          >
          does not work when the list contains 10/07/2006
          and the value returned by someClass.Begin Date.ToShortDat eString() is
          10/7/2006
          >
          How can I set this list value to be the date returned frm the class?
          >
          Thanks
          Jeff

          Comment

          • Bob Jones

            #6
            Re: DateTime in dropdown

            Maybe I'm not understanding something here, but why don't you handle
            the dates as DateTime objects? Date objects are easily compared. If
            they are already strings - coming from the selection list- cast them to
            DateTime, compare, then convert back to string.


            On 2006-10-26 14:21:13 -0500, Jeff User <jeff31162@hotm ail.comsaid:
            >
            The dropdown is a list of dates. I have to find the index of the date
            desired to set it as the selected item in the list. The desired value
            being the date with only the 1 digit for the day, the list items being
            the dates with 2 digits. I spose I can add the zero to the 1 digit day
            to make it match the dropdown date format.
            I was wondering if there was some way to use formating to get one to
            look like the other.
            >
            Thanks
            >
            On 26 Oct 2006 10:31:09 -0700, "justin creasy"
            <justin.creasy@ gmail.comwrote:
            >
            >Jeff,
            >>
            >Does the value have to be stored in SelectedIndex or could you
            >subscribe to the SelectedIndexCh anged event, and when you catch the
            >event do the processing needed to remove the extra digit and place it
            >into another variable.
            >>
            >Jeff User wrote:
            >>Hi all
            >>>
            >>The date values in my dropdown list appear as mm/dd/yyyy
            >>Specificall y, the day always contains 2 digits.
            >>I need to set the selected index of the dropdown to the date that
            >>equals another date value that does not use 2 digits for the day, if
            >>the day is less that 10.
            >>example
            >>ddlBeginDate. SelectedIndex =
            >>ddlBeginDate. Items.IndexOf(d dlBeginDate.Ite ms.FindByText(s omeClass.BeginD ate.ToShortDate String()));
            does
            >>>
            >>>
            >>does not work when the list contains 10/07/2006
            >>and the value returned by someClass.Begin Date.ToShortDat eString() is
            >>10/7/2006
            >>>
            >>How can I set this list value to be the date returned frm the class?
            >>>
            >>Thanks
            >>Jeff

            Comment

            Working...