Click here to Skip to main content
16,020,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three dropdownlist as follows


From Date Dropdownlist1 Dropdownlist2 Dropdownlist3
(Date) (Month) (Year)


i want to show the today Date in Dropdownlist1
today Month in Dropdownlist2
today Year in Dropdownlist3


For that how can i do using csharp.


please help me.


For example today's date 7th October 2013

In dropdownlist1 shows Date 7
In dropdownlist2 shows Month October
In dropdownlist3 shows Year 2013

for the above how can i do using asp.net in csharp.

Regards,
narasiman P.
Posted
Comments
Richard MacCutchan 7-Oct-13 6:35am    
Why not just use a Calendar control?
BulletVictim 7-Oct-13 6:44am    
On load set the selected value of the dropdownlist to System.DateTime.Now."Your selection of each dropdownlist"
But as Richard suggested, try using a calander Control, should work a lot easier and have less checks you will need to run to validate the correct date

DateTime Currdt = Convert.ToDateTime(System.DateTime.Now.ToString());



DropDownList1.Items.Insert(0, Currdt.Day.ToString());
DropDownList1.Items[0].Value = Currdt.Day.ToString();

DropDownList2.Items.Insert(0, Currdt.Month.ToString());
DropDownList2.Items[0].Value = Currdt.Month.ToString();


DropDownList3.Items.Insert(0, Currdt.Year.ToString());
DropDownList3.Items[0].Value = Currdt.year.ToString();
 
Share this answer
 
hello Professional

you can do that like this..

// this is for Year
C#
void fillYears()
   {
       ddlYear.Items.Clear();

       //
       for (int i = 1990; i <= DateTime.Now.Year; i++)
       {
           ddlYear.Items.Add(i.ToString());

       }
       ddlYear.Items.Insert(0, new ListItem("Year", "0"));
   
   }


as above you can bind with
DateTime.Now.Month

and also
DateTime.Now.Date


hope this will help you



Happy to Help!!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900