在下拉列表中显示今天的日期 [英] In Dropdownlist shows the today's date

查看:87
本文介绍了在下拉列表中显示今天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个下拉列表如下





来自日期Dropdownlist1 Dropdownlist2 Dropdownlist3

(日期)(月)(年)





i想要显示今天Dropdownlist1中的日期

今天月份Dropdownlist2

今天下拉列表3





为此我怎样才能使用csharp。





请帮帮我。





例如今天的日期2013年10月7日



在dropdownlist1中显示日期7

在dropdownlist2中显示月份10月

在dropdownlist3中显示2013年



以上如何在csharp中使用asp.net。



问候,

narasiman P.

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.

推荐答案

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();

< br $>


DropDownList3.Items.Insert(0,Currdt.Year.ToString());

DropDownList3.Items [0] .Value = Currdt .year.ToString();
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();


你好专业



你可以这样做..



//这是年度

hello Professional

you can do that like this..

// this is for Year
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!!!


http://www.webcodeexpert .com / 2013/04 / how-to-fill-dropdown-with-days-month.html#.UlMHx9Jgc6o [ ^ ]试试这个


这篇关于在下拉列表中显示今天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆