简体   繁体   中英

Two tables in one dropdown list asp.net mvc4

I have 2 different tables and I want to make them in one drop down list, Is this possible?

this for my dropdownlist Controller. I added some items because that items are not in table.

var engineer = 
(from x in up5.V_Pekerja.Where(x => x.KodeBagian == "E15320" && 
          x.NamaJabatan.ToLower().Contains("section head") == false && 
          x.NamaJabatan.ToLower().Contains("lead of") == false)
  select new 
   SelectListItem { Text = x.Nopek + " - " + x.Nama, Value = x.Nopek }).ToList();

  engineer.Add(new SelectListItem { Text = "663693 - Nana Sukarna", Value = "663693" });
  engineer.Add(new SelectListItem { Text = "653479 - Tri Bambang H", Value = "653479" });
  engineer.Add(new SelectListItem { Text = "747522 - Apri Marlinaldi Majid", Value = "747522" });
  ViewBag.Engineer = engineer;

can someone please help me if this possible.. sorry for my bad english

您没有提到第二张表的想法,但是您可以尝试通过以下方式将其添加到SelectListItem中:

List<SelectListItem> table2 = new List<SelectListItem>(); //define your table2 engineer.AddRange(table2);

I found the following article that looks like it has the information you need. The loading of the dropdown is similar to how I was going to approach it. The article below takes it a step further and show how to load the data for the selected record and display it. Depending on what you are doing that additional information may or may not be beneficial.

C# Corner: Binding To Table To DropDown

Hope the information helps you answer your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM