如何让dropdownlist中的项目对用户不可见? [英] How to make items in dropdownlist not visible to user?

查看:69
本文介绍了如何让dropdownlist中的项目对用户不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除存储在数据库中的下拉列表中的某些项目。我有一个沙龙的预约管理系统,用户可以预约约会。因此,当用户点击第一个下拉列表时,该列表包含从今天到下一个60天的日期。它应该在数据库中检查该日期是否可用于预约,这取决于另一个下拉列表中的时间。例如:在第二个下拉列表中,我有时间从09:00到09:30。当用户从第一个下拉列表中选择日期时,它应该在数据库中检查该特定日期的时间是否可用。如果不是该日期不应该对用户可用。有人告诉我建立一个类型字符串列表。从今天的日期到数据库中的所有约会从未完全预订日期的60天。所以你将获得所有可用日期的列表。



现在计算列表中的项目数。如果计数小于60,则从列表中获取最后一个日期并添加上次日期的日期,直到列表变为60 。



然后使用.shortdatetime.tostring将datetime数据类型转换为字符串并将其绑定到下拉控件。



对于存储约会,我使用此表:

How can I remove some items of a dropdownlist which are stored in database. I have an appointment management system for a salon in which users can book appointments. So when a user clicks on first dropdownlist which consists of dates from today till next 60 days. It should check in the database whether that date is available for appointment or not which is based on time which is in another dropdownlist. For example: in second dropdownlist I have time from 09:00 AM to 09:30 PM. When the user selects a date from first dropdownlist then it should check in the database whether time on that particular date is available or not. If not than that date should not be available for the user. Somebody told me to "Build a list of type string. Pull all appointments from database from today's date to next 60 days where day is not fully booked. So u will get list of all dates that are available.

Now do a count of the number of items in the list. If the count is less than 60 then get the last date from the list and add dates from last date until the list becomes of size 60.

Then convert the datetime data type to string using .shortdatetime.tostring and bind it to the dropdown control."

For storing appointments I am using this table:

TABLE [dbo].[Appointments] (
    [Name]              NVARCHAR (100)   NOT NULL,
    [ShopperId]         UNIQUEIDENTIFIER NOT NULL,
    [Date]              DATE             NOT NULL,
    [Time]              TIME (7)         NOT NULL,
    [AppointmentNo]     INT              IDENTITY (1, 1) NOT NULL,
    [AppointmentStatus] NVARCHAR (100)   NOT NULL,
    [Services]          NVARCHAR (1000)  NOT NULL)





并存储由管理员添加的服务,而不是在checkboxlist中绑定这些服务。服务表是:





And to store services which are added by admin and than I bind these in checkboxlist. The service table is:

TABLE [dbo].[AddService] (
    [ServiceId]        UNIQUEIDENTIFIER NOT NULL,
    [ServiceName]      NVARCHAR (500)   NOT NULL,
    [DurationRequired] Date         NOT NULL,
    [Description]      NVARCHAR (2000)  NOT NULL,
    [Active]           BIT              NOT NULL)







以下代码将日期添加到一个下拉列表和时间到另一个下拉列表:






The below code adds date to one dropdownlist and time to another dropdownlist:

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        using (AppointmentDataContext context = new AppointmentDataContext())
        {

            var query = (from p in context.Accounts //for getting name form database of the user logged in
                         where p.Email == Session["login"]
                         select p.Name).SingleOrDefault();
            TextBoxName.Text = query.ToString();
        }

        DropDownListDate.Items.Add(DateTime.Now.ToShortDateString()); //for adding current date
        for (int i = 1; i <= 59; i++) //loop to add next 60 days
        {
            DropDownListDate.Items.Add(DateTime.Now.AddDays(i).ToShortDateString());
        }

        DateTime dt = Convert.ToDateTime("09:00"); //for adding start time
        for (int i = 0; i <= 25; i++) //Set up every 30 minute interval
        {
            ListItem li2 = new ListItem(dt.ToShortTimeString(), dt.ToShortTimeString());
            li2.Selected = false;
            DropDownListTime.Items.Add(li2);
            dt = dt.AddMinutes(30);
        }
    }

    catch (Exception ex)
    {
        Response.Write(ex);
    }
}





我尝试了下面编写的代码,但没有帮助:





I tried the below written code but did not helped:

var qry = from d in context.Appointments
                      select d.Date;

            var qry1 = from t in context.Appointments
                       select t.Time;

            String test = qry1.ToString();
            TimeSpan time = TimeSpan.Parse(test);

            if (qry == DateTime.Parse(DropDownListDate.Items.ToString()) && time == TimeSpan.Parse(DropDownListTime.Items.ToString()))
            {
                //what should I write over here.
            }

推荐答案

这一切都取决于你的数据库数据和你可能的代码逻辑设计供用户使用。



如前所述,只有这样才能将Item添加到应用程序的DropDrownList中。您可以通过检查数据库中的记录来执行此操作,如果它返回true(记录未找到),则添加它,否则不要添加它。



无法在列表中添加隐形项目。
This all depends on the database data of yours and the code logic that you might design for the users to use.

As already said, only way to do this is to not add the Item to the DropDrownList of your application. You can do so, by checking for a record in your database, if it returns true (record not found) then add it, otherwise don't add it.

Adding an Invisible Item in the list is not possible.


非常简单亲爱的。

只需从db获得所有约会。

然后在你用来绑定时间检查包含的循环中。我的意思是

这样的ckeck

Its very simple dear.
Just get all the appointments from db.
then in the loop that you are using to bind the time check for contains. I mean
ckeck like this
if(!dbApointments.contains(date+time))
{
   dt.rows.add(row);
}





使用此逻辑来实现您的代码。



use this logic to implement your code.


您可以简单地在数据库查询中执行此操作,方法是按升序从数据库中获取接下来的60天,按时间顺序按升序排列前60个日期。
You Can simply do this in your DB Query by getting next 60 days from your DB in ascending order , BY using top 60 dates in ascending order where time is available.


这篇关于如何让dropdownlist中的项目对用户不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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