Solved

asp.net vb display current year in dropdownlist

Posted on 2010-09-18
7
637 Views
Last Modified: 2012-05-10
How would i modify this dropdownlist item to display the current year as both the value and the display?

<asp:listitem value="current year here" selected="true">and current ear here</asp:listitem>

Thanks
0
Comment
Question by:elliottbenzle
7 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 33708786
Could you set the value in the code behind it?

asp like this  <asp:DropDownList ID="DropDownList1" runat="server" Height="59px"></asp:DropDownList>

then in code like this

 DropDownList1.Items.Add(Year(Now()));
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33708802
Might need to tostring the year(now) bit if it complains

in order to selected the display value you can use selected value

eg see this example (in c#) where I added 3 entries in my dropdownlist. I set the selected value by using the value I want

        DropDownList1.Items.Add("2009");
        DropDownList1.Items.Add(dt.Year.ToString());
        DropDownList1.Items.Add("2011");
        DropDownList1.SelectedValue = dt.Year.ToString();
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33708816
Yes, I would do it with ToString() and remember you can do this inline.

ddlYear.Items.Add(new ListItem(DateTime.Today.ToString("yyyy"), DateTime.Today.ToString("yyyy"), true))
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33708819
That way you also set the enabled to true in one go.
0
 
LVL 5

Expert Comment

by:FredTang
ID: 33709900
               dim Item_year as Listitem
                lItem_year = new ListItem();
                lItem_year.Text = Year(Now()).toString();
                lItem_year.Value = Year(Now()).toString();
                this.DropDownList1.Items.Add(lItem_year);

hopes this code could help you.
0
 
LVL 4

Author Closing Comment

by:elliottbenzle
ID: 33710188
Thanks
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33710207
No worries :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now