dynamic drop downs

I

igotyourdotnet

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
 
S

Steven Cheng[MSFT]

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.
 
G

Guest

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.
 
G

Guest

Mike,

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

Steven Cheng[MSFT]

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.
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top