0
我有一個4字符串類。我試圖通過使用ServiceController遍歷每個Windows服務,然後將其綁定到類對象的列表。通過LINQ查詢將ServiceController對象綁定到列表
這兩個選項會更好,怎麼做他們兩個
我的目標是這個列表綁定到GridView的數據源。
public class ServiceDetails
{
public string ServiceName { get; set; }
public string Status { get; set; }
public string Description { get; set; }
public string Location { get; set; }
}
protected void GetAllServices(string machinename)
{
ServiceController[] services = ServiceController.GetServices(machinename);
List<ServiceDetails> svcdetails = new List<ServiceDetails>();
// option 1 - to iterate through each and bind to list
foreach (ServiceController service in services)
{
//How to bind the servicecontroller object to a list.?
}
// option 2 - Bind the List using LINQ query
List<ServiceDetails> items = svcdetails.ForEach(service=> LINQ Query...?
Gridview.DataSource = items;
Gridview.DataBind();
}