tags:

views:

1533

answers:

2

Hi all, I wanna add the current month and the last 2 months for user to select in prompt, e.g. if this month is 2008 Nov, then I wil see foowing in ddlbox 112008 102008 092008

may I know how to do it? no hard-code

A: 
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

  for (int i = 0; i < 3; i++)
            {
                ListItem item = new ListItem(string.Format("{0: MM/yyyy}",DateTime.Now.AddMonths(-i)));
                DropDownList1.Items.Add(item);
            }

Try this :)

VB For the WIN
A: 

You could also create a query subject with SQL like this Oracle example:

SELECT to_char(add_months(SYSDATE, -1 * LEVEL + 1), 'MMYYYY') AS mon
FROM   dual
CONNECT BY rownum < 4
Richard Cresswell