Solved

asp.net vb display current year in dropdownlist

Posted on 2010-09-18
7
677 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
[X]
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
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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

762 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