Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

asp.net vb display current year in dropdownlist

Posted on 2010-09-18
7
672 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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