dynamic drop downs

Discussion in 'ASP .Net' started by igotyourdotnet, Dec 6, 2006.

  1. i have 2 drop downs that have months in them such as
    1/1/2005 and 1/31/2005

    I need to my starting month drop down to be a month behind the end of month

    so something like this:
    if month ending = 1/31/2006
    I need start month = 12/31/2005

    how can I do thi? is it possible?
    its kind of a backwards thing, but the month end dropdown can be populated
    from a querystring so if 1/31/2006 is passed I need to set the start month
    to be 12/31/2005
     
    igotyourdotnet, Dec 6, 2006
    #1
    1. Advertising

  2. Hello Mike,

    From your description, you have an ASP.NET page which has two dropdownlists
    and they'll display two month values and you want to make one list's
    selected month 1 month behind another(start and end), correct?

    As for this scenario, I think it is a typical dropdownlist synchornize
    issue, I'm wondering how would like to implement the synchronizing between
    the two values, use server-side code logic or client-side script?

    Generally, most page will use client script to manipulate such cascading
    value changes in associated dropdownlists. you can hook the
    dropdownlist(<select> html element)'s client-side "onchange" event. BTW,
    are the months items in each list fixed? For example, both of the list only
    contains 12 months(items)? If so, you can even use selectedIndex value to
    determine how to adjust each list's selected value.

    Please feel free to let me know your detailed scenario and requirement.


    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Dec 6, 2006
    #2
    1. Advertising

  3. If you are doing it server-side you can determine the startDate doing
    something like this:

    'This is where you would convert your querystring to a datetime object
    Dim endDate As DateTime = System.Convert.ToDateTime("1/31/2006")

    'startDate will be the last day of the month previous to the endDate
    Dim startDate As DateTime =
    endDate.AddDays(-endDate.DaysInMonth(endDate.Year, endDate.Month))

    You could then select the listbox item that matches the date.

    Like Steven said, most people do this on the client-side so that you don't
    have to do a post-back to figure out what to select in the dropdown. If you
    know JavaScript its not that hard to do.

    --
    Nick Wegner



    "Steven Cheng[MSFT]" wrote:

    > Hello Mike,
    >
    > From your description, you have an ASP.NET page which has two dropdownlists
    > and they'll display two month values and you want to make one list's
    > selected month 1 month behind another(start and end), correct?
    >
    > As for this scenario, I think it is a typical dropdownlist synchornize
    > issue, I'm wondering how would like to implement the synchronizing between
    > the two values, use server-side code logic or client-side script?
    >
    > Generally, most page will use client script to manipulate such cascading
    > value changes in associated dropdownlists. you can hook the
    > dropdownlist(<select> html element)'s client-side "onchange" event. BTW,
    > are the months items in each list fixed? For example, both of the list only
    > contains 12 months(items)? If so, you can even use selectedIndex value to
    > determine how to adjust each list's selected value.
    >
    > Please feel free to let me know your detailed scenario and requirement.
    >
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
     
    =?Utf-8?B?TmljayBXZWduZXI=?=, Dec 6, 2006
    #3
  4. Mike,

    So, did you want to do this client side or server side? Do you still need
    help with this?

    --
    Nick Wegner



    "igotyourdotnet" wrote:

    > Both list are fixed and contain 12 months for the passed 10 years. So they
    > can have dates from 11/01/2006 back to 1/1/1998.
    >
    > so if 11/31/2005 is passed as the ending date I need 10/01/2005 as the start
    > date.
    >
    >
    > "Steven Cheng[MSFT]" wrote:
    >
    > > Hello Mike,
    > >
    > > From your description, you have an ASP.NET page which has two dropdownlists
    > > and they'll display two month values and you want to make one list's
    > > selected month 1 month behind another(start and end), correct?
    > >
    > > As for this scenario, I think it is a typical dropdownlist synchornize
    > > issue, I'm wondering how would like to implement the synchronizing between
    > > the two values, use server-side code logic or client-side script?
    > >
    > > Generally, most page will use client script to manipulate such cascading
    > > value changes in associated dropdownlists. you can hook the
    > > dropdownlist(<select> html element)'s client-side "onchange" event. BTW,
    > > are the months items in each list fixed? For example, both of the list only
    > > contains 12 months(items)? If so, you can even use selectedIndex value to
    > > determine how to adjust each list's selected value.
    > >
    > > Please feel free to let me know your detailed scenario and requirement.
    > >
    > >
    > > Sincerely,
    > >
    > > Steven Cheng
    > >
    > > Microsoft MSDN Online Support Lead
    > >
    > >
    > >
    > > ==================================================
    > >
    > > Get notification to my posts through email? Please refer to
    > > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > > ications.
    > >
    > >
    > >
    > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > > where an initial response from the community or a Microsoft Support
    > > Engineer within 1 business day is acceptable. Please note that each follow
    > > up response may take approximately 2 business days as the support
    > > professional working with you may need further investigation to reach the
    > > most efficient resolution. The offering is not appropriate for situations
    > > that require urgent, real-time or phone-based interactions or complex
    > > project analysis and dump analysis issues. Issues of this nature are best
    > > handled working with a dedicated Microsoft Support Engineer by contacting
    > > Microsoft Customer Support Services (CSS) at
    > > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > >
    > > ==================================================
    > >
    > >
    > >
    > > This posting is provided "AS IS" with no warranties, and confers no rights.
    > >
    > >
     
    =?Utf-8?B?TmljayBXZWduZXI=?=, Dec 7, 2006
    #4
  5. Hi Mike,

    Here is a simple example page which use pure client-side script to
    synchornize the two dropdownlist(<select>), both of them contain 24 months:

    ===================================
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function sync_lists(source)
    {
    var lst1 = document.getElementById("lstStart");
    var lst2 = document.getElementById("lstEnd");




    if(lst1.selectedIndex == lst1.options.length-1)
    {
    lst1.selectedIndex = lst2.selectedIndex - 1;
    }
    else if(lst2.selectedIndex == 0)
    {
    lst2.selectedIndex = lst1.selectedIndex + 1;
    }
    else
    {

    if(source == 0)
    {
    lst2.selectedIndex = lst1.selectedIndex + 1;
    }
    else
    {
    lst1.selectedIndex = lst2.selectedIndex - 1;
    }
    }
    }

    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <select id="lstStart" name="lstStart" onchange="sync_lists(0);" >
    <option selected="selected" >06-01</option>
    <option>06-02</option>
    <option>06-03</option>
    <option>06-04</option>
    <option>06-05</option>
    <option>06-06</option>
    <option>06-07</option>
    <option>06-08</option>
    <option>06-09</option>
    <option>06-10</option>
    <option>06-11</option>
    <option>06-12</option>
    <option>07-01</option>
    <option>07-02</option>
    <option>07-03</option>
    <option>07-04</option>
    <option>07-05</option>
    <option>07-06</option>
    <option>07-07</option>
    <option>07-08</option>
    <option>07-09</option>
    <option>07-10</option>
    <option>07-11</option>
    <option>07-12</option>
    </select>

    <select id="lstEnd" name="lstEnd" onchange="sync_lists(1);">
    <option >06-01</option>
    <option selected="selected">06-02</option>
    <option>06-03</option>
    <option>06-04</option>
    <option>06-05</option>
    <option>06-06</option>
    <option>06-07</option>
    <option>06-08</option>
    <option>06-09</option>
    <option>06-10</option>
    <option>06-11</option>
    <option>06-12</option>
    <option>07-01</option>
    <option>07-02</option>
    <option>07-03</option>
    <option>07-04</option>
    <option>07-05</option>
    <option>07-06</option>
    <option>07-07</option>
    <option>07-08</option>
    <option>07-09</option>
    <option>07-10</option>
    <option>07-11</option>
    <option>07-12</option>
    </select>
    </div>
    </form>
    </body>
    </html>
    ======================================

    Hope this helps some.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Dec 8, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davmagic .Com

    Need Script For Drop Downs

    Davmagic .Com, Oct 14, 2004, in forum: Perl
    Replies:
    0
    Views:
    453
    Davmagic .Com
    Oct 14, 2004
  2. jaysch
    Replies:
    0
    Views:
    1,245
    jaysch
    Apr 30, 2011
  3. None

    Dynamic Drop Downs

    None, Oct 2, 2004, in forum: Javascript
    Replies:
    0
    Views:
    110
  4. MiG
    Replies:
    3
    Views:
    122
    Erwin Moller
    Sep 10, 2007
  5. morc

    Dynamic Drop Downs PHP AJAX

    morc, Feb 17, 2010, in forum: Javascript
    Replies:
    0
    Views:
    157
Loading...

Share This Page