Click here to Skip to main content
15,889,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to remove times of a particular date from a dropdownlist which are stored in database. I have used two dropdownlist for date and time. I want to remove only times which are already stored in the database. I am using SQL database. This is to be done for an appointment management system.
Posted
Updated 31-Oct-14 21:40pm
v2
Comments
Afzaal Ahmad Zeeshan 1-Nov-14 4:06am    
What do you mean by Remove Items? Do you want to remove them from the SQL database, or just from the DropDownList in the runtime?
Amit Jangid 1-Nov-14 4:19am    
Just from the dropdownlist in runtime. It should be visible if not stored in database but invisible is stored in database. Can you help me out with 5 users?
Afzaal Ahmad Zeeshan 1-Nov-14 6:55am    
You mean, that if the user has that value in database, then it must not be shown otherwise it should be shown to him?

Are you using a Condition for each of the users?

Last thing, would there be a few options for each and the user can select only one at a time? Something like this?
Amit Jangid 1-Nov-14 7:02am    
You are right. If that particular time is stored in database than it should not be showed to the user for both date dropdownlist and time dropdownlist. The time selection is based on services. The condition is based on the Service selection. The system is for salon. So if the user selects different services than the duration of all the different services needs to be added.
swarjadhav 1-Nov-14 12:14pm    
Bind all Items to dropdown;
then check for each whether user has that value or not
if Present then
{
dropdownListName.Items.RemoveAt(dropdownListName.Items.IndexOf(dropdownListName.Items.FindByText("field_to_remove")));
}

1 solution

1. Bring all items (time/date/whatever) stores in database and save it in a json(may be in a hidden field) on the page.

2. Remove the item in drop down which is present in the json list.

SQL
$("option[value='foo']").remove();

or better (if you have few selects in the page):

$("#select_id option[value='foo']").remove();



For step two, you actually have to loop through the json and remove the matching element in the drop down.

Check the following example on how to loop over json:

PHP
var data = [
 {"Time": 1PM, },
 {"Time": 2PM, },
 {"Time": 5PM, }
];

$.each(data, function(i, item) {
     //alert(data[i].Time);
     $("#select_id option[value=data[i].Time]").remove();

});​
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900