Enrique Gil
Enrique Gil

Reputation: 754

How to Prevent Drop down to show values that is in Database

I want to prevent the value of the dropdown list when it is already in the database file so that theres no multiple input in the Database ,

I hope someone can Help me with this problem ,

I'm using MVC 3 and Kendo UI

is that possible to handle it via Jquery or a Linq Statement in the Controller ?

Thanks :)

 <span>
                @Html.DropDownList("ddlDay", new SelectList(ViewBag.DayList, "ID", "Display_Value", PersonDay), "[Please Select]",
          new Dictionary<string, object>
                {
                    {"class","validate[required] inputLong"}
                })
            </span>

This Dropdown Show Monday to Sunday , i have 2 of this drop down that shows availability But i like to know that if i save Monday to Wednesday , Monday to Wednesday is removed on the two dropdowns ,

private void GetDayList()
        {
            var dayList = (from a in db.Lookups
                              where a.Domain == "DAYSTATUS"
                              select a).ToList();

            ViewBag.DayList = dayList ;
        }

Upvotes: 0

Views: 164

Answers (1)

Timothy Walters
Timothy Walters

Reputation: 16874

You can solve this in many ways, it will depend on how your interaction is done.

You could use LINQ, adding a Where() or Except() statement to filter the full list:

var fromDayList = dayList.Where(day => day.Name != selectedFromDay).ToList();
// or if multiple selected days, assuming it is of the same type:
var validDayList = dayList.Except(selectedDayList).ToList();

If you allow them to change the selected days client side and are using AJAX (which is how you usually use Kendo UI) then you won't want to filter server side. Instead you should wrap your DayList in a kendo.DataSource and apply a filter based on selected days in your JavaScript. You haven't provided enough information for me to supply any sample code for this.

Upvotes: 1

Related Questions