我需要列表框中的选项组以及选项组中的其他列表。
需要建筑物作为选项组,并且在其中需要服务作为选项。
如图所示的示例
在这里,我需要管理员作为选项组的建筑物名称( ),并保持服务选项的建筑物名称()。
代码如下所示:-
var en = new HorizonEntities();
//Service for options
var serviceStreams = (from x in en.ServiceStreams
where x.IsActive == true
select x).OrderBy(a => a.ServiceStreamName).ToList();
var clientSiteId = Guid.Parse(cbo_Sites.SelectedItem.Value);
//client site buildings as option group...
var clientSiteBuildings = (from x in en.ClientSiteBuildings
where x.ClientSiteId == clientSiteId
select x).OrderBy(a => a.ClientSiteBuildingName).ToList();
cbo_ServiceStream.Items.Clear();
foreach (ClientSiteBuilding clientSiteBuilding in clientSiteBuildings)
{
ListItem item = new ListItem();
//item.Attributes["OptionGroup"] = clientSiteBuilding.ClientSiteBuildingName;
//item.Text = clientSiteBuilding.ClientSiteBuildingName;
//cbo_ServiceStream.Items.Add(item);
item.Attributes["OptionGroup"] = clientSiteBuilding.ClientSiteBuildingName;
item.Text = clientSiteBuilding.ClientSiteBuildingName;
cbo_ServiceStream.Items.Add(item);
cbo_ServiceStream.Items.Add(new ListItem(clientSiteBuilding.ClientSiteBuildingName, clientSiteBuilding.ClientSiteBuildingId.ToString()));
foreach (ServiceStream serviceStream in serviceStreams)
{
cbo_ServiceStream.Items.Insert(0, new ListItem(serviceStream.ServiceStreamName, serviceStream.ServiceStreamId.ToString()));
}
}
cbo_ServiceStream 是列表框适配器, clientSiteBuildings 是选项组的构建要求,而选项组的 serviceStreams 。