基于数据库记录的下拉列表中的加载日期 [英] Loading date in dropdown based on database records

查看:67
本文介绍了基于数据库记录的下拉列表中的加载日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想根据数据库记录隐藏日期.也就是说,如果该日期具有记录,则意味着我要在下拉列表中显示日期,否则该日期将隐藏在下拉列表中. 我该怎么做..

string [] date =新的string [8];
DateTime dt = DateTime.UtcNow.AddHours(5.5);
DropDownList1.Items.Insert(0,-SELECT DATE--");
DropDownList1.Items.Insert(1,new ListItem(dt.ToString("MM/dd/yyyy"))));
for(int i = 1; i< 3; i ++)
{
字符串s = dt.AddDays(-i).ToString("MM/dd/yyyy");
DropDownList1.Items.Insert(1 + i,新的ListItem(s,s));
}
这是我加载日期的代码.我已经在pageload()中调用了它.我需要在下拉列表中显示三个日期.
如果日期没有值,则意味着我需要在下拉列表中显示日期.否则,无需显示..
任何人都可以帮助我吗?

Hi
i want to hide the date based on the database record.That is if the date is having record means i want to display date in dropdown list otherwise the date is to be hide in the dropdownlist..
how can i done this..

string[] date = new string[8];
DateTime dt = DateTime.UtcNow.AddHours(5.5);
DropDownList1.Items.Insert(0,"--SELECT DATE--");
DropDownList1.Items.Insert(1, new ListItem(dt.ToString("MM/dd/yyyy")));
for (int i = 1; i < 3; i++)
{
string s = dt.AddDays(-i).ToString("MM/dd/yyyy");
DropDownList1.Items.Insert(1+i, new ListItem(s, s));
}
this is my code to load date.i have call this in pageload().Three dates i nedd to display in dropdownlist.
if the date is not having values means i need to display date in dropdown..otherwise no need to display..
Can any one help me?

推荐答案

那么您要面对什么问题.如果已将所有项目都放在aspx中,则可以在加载"事件的下拉列表中删除这些项目(日期).

或者更好的是,您可以从数据库中获取所有可能的日期并动态绑定下拉列表.
So what problem you are facing. If you have put all the items in aspx then you can remove the items(dates) from the dropdownlist on Load event.

Or better you get all possible dates from database and bind the dropdown dynamically.


这篇关于基于数据库记录的下拉列表中的加载日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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