如何在下拉列表中设置日期 [英] How Do I Set Date In Dropdownlist
本文介绍了如何在下拉列表中设置日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在asp.net的下拉列表中设置当前日期..我尝试使用ddldate.selectedvalue = system.datetime.now,也无法使用ddldate.text = system.datetime.now... .谁能说出如何在dropdownlist中设置值..我无法获得确切的答案来解决搜索引擎中的问题..任何帮助??
i am trying to set current date in dropdown list in asp.net.. i have tried with ddldate.selectedvalue = system.datetime.now, also, ddldate.text = system.datetime.now.. its not working.. can anyone tell how to set value in dropdownlist.. i couldnot get the exact answer to resolve my problem in search engine.. any help??
推荐答案
下拉列表仅包含一项
那对你有帮助..
if you dropdownlist contains only one item
then this will help you..
ddlLeaveStartdate.Items.Add(DateTime.Now.ToString("MM/dd/yyyy"));
使用以下语法...
ddldate.Items.FindByText(system.datetime.now).Selected = true
Use the following syntax...
ddldate.Items.FindByText(system.datetime.now).Selected=true
您可以在下拉列表中具有选定值的列表中可用.
因此,首先添加列表项,然后设置值.
像
You can have a selected value in the dropdownlist once its available in the list.
So first add the list item then set the value.
Something like
ddl.Items.Add(new ListItem(DateTime.Now.ToString()));
ddl.SelectedValue = DateTime.Now.ToString();
这篇关于如何在下拉列表中设置日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文