[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

asp.net vb display current year in dropdownlist

Posted on 2010-09-18
7
Medium Priority
?
706 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 2000 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 60

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 60

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

830 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