如何在下拉列表中增加学年? [英] How to add academic years in dropdownlist?
本文介绍了如何在下拉列表中增加学年?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在下拉列表中添加学年(以编程方式).
例如:2010-2011,
2011-2012年等
请解决我的问题
Hi,
How to add academic years in dropdownlist(Programatically).
Eg: 2010-2011,
2011-2012 etc.
Please solve my problem
推荐答案
^ ]
使用日期时间 [ ^ ]来获取年份,并进行字符串串联(例如2010-2011年)&将其添加到下拉列表.
DateTime.Now.Year()
将返回当前年份.
编辑
同意普拉萨德.将值存储在数据库中将其加载到下拉列表中.考虑这是您的表格(Academic_Years).
Use DateTime[^] to get the years, do string concatenation(Ex. 2010-2011) & add it to dropdownlist.
DateTime.Now.Year()
will return current year.
EDIT
Agree with Prasad. Store values in database & load it in dropdownlist. Consider this is your table(Academic_Years).
Years
--------------
2008-2009
2009-2010
2010-2011
2011-2012
--------------
使用以下查询选择数据
Use below query to select the data
SELECT * FROM Academic_Years
编写类似下面的代码
Write code something like below
DataTable dt = GetYears();//Custom function to load Academic years from database
dropdownlist.DataSource = dt;
dropdownlist.DataBind();
最后,我建议您学习所有内容 ASP.NET教程@ W3Schools [
Finally I suggest you to learn everything ASP.NET Tutorial @ W3Schools[^]
Hari,
请在Page_Load()事件中使用此代码
Hi Hari,
Please use this code in the Page_Load() event
if (!Page.IsPostBack)
{
for (int i = 2000; i <= 2012; i++)
{
int next = i + 1;
DropDownList1.Items.Add(i.ToString() + "-" + next.ToString());
}
}
如果此操作可以解决您的问题,请设为已解决",
如有任何疑问,请回复我.
感谢和问候
苏曼·扎洛迪亚(Suman Zalodiya)
Please make as Resolved if this resolves your issue,
Please revert back to me in case of any cocnerns.
Thanks And Regards
Suman Zalodiya
这篇关于如何在下拉列表中增加学年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文