Click here to Skip to main content
15,878,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have listbox

@Html.ListBox("lais", new SelectList(Model.lista, "Value", "Text"), new {@class = "mylistbox"});

Here am getting list data but not binding to listbox (list items value )

This is my action method

public ActionResult PrintRFIDTag()
{
Print p =new Print();
p.lista = GetList();

return View(p);

}

public SelectList GetList()
{
System.Management.ManagementScope objMS =
new System.Management.ManagementScope(ManagementPath.DefaultPath);
objMS.Connect();
List<SelectListItem> items = new List<SelectListItem>();
SelectQuery objQuery = new SelectQuery("SELECT * FROM Win32_Printer");
ManagementObjectSearcher objMOS = new ManagementObjectSearcher(objMS, objQuery);
System.Management.ManagementObjectCollection objMOC = objMOS.Get();
foreach (ManagementObject Printers in objMOC)
{
if (Convert.ToBoolean(Printers["Network"])) // ALL NETWORK PRINTERS.
{
var emptyItem = new SelectListItem()
{
Value = Printers["Name"].ToString(),
Text = "00"
};

items.Add(emptyItem);

}
}
SelectList objselectlist = new SelectList(items,"Value");
return objselectlist;
}

}

Here is my model class

public class Print
{
public SelectList lista { get; set; }
public string Name { get; set; }
}

Returning from view but not binding to listbox Your help will be appropriated
Posted

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