嗨,我只是想开始说我对LINQ和.NET非常陌生。我正在尝试使用linq查询获取一组数据,并将数据填充为我的listview中的HTML表头。我无法对标题进行硬编码,因为对于运行查询的每个组织而言,标题都不相同。如何通过linq查询结果循环并将结果添加到列表视图中的Html表头
下面是一个查询,其中即时得到所有的配置文件名称为组织的一个例子,我想有每个配置文件在我的列表视图表头:
var organizationProfiles =
(from profile in orgWorkProfiles.WorkProfiles
join org in orgWorkProfiles.Organizations on new { profile.OrganizationId } equals new { OrganizationId = org.Id }
where org.Name == ddlOrg1.SelectedItem.ToString()
select profile.Name);
,这是我的列表视图看起来像在展示页面:
<asp:ListView ID="ltv_main" runat="server">
<LayoutTemplate>
<table id="reportTable" width="100%">
<thead class="headRowDetails" >
<th class="headRowDetails">Profile1</th>
<th class="headRowDetails">Profile2</th>
<th class="headRowDetails">Profile3</th>
<th class="headRowDetails">Profile4</th>
<th class="headRowDetails">Profile5</th>
</thead>
<tbody>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="normRowDetails">
<td>Eval some data here</td>
<td>Eval some data here</td>
<td>Eval some data here</td>
<td>Eval some data here</td>
<td>Eval some data here</td>
</tr>
</ItemTemplate></Listview>
正如你们可以看到我目前硬编码在表头,但这是必需的不是,我想是能够使头动态。有人能帮我解决这个问题吗?如果无法在列表视图中动态创建标题,是否有替代解决方案?非常感谢您的帮助。提前致谢!
您的问题对我来说并不清楚......如果我理解正确,您描述的Linq查询返回配置文件名称...我错过查询返回您想要放入标题的值? – Yahia
嗨Yahia。配置文件名称是我想用作标题的值。问题是我不知道如何将列表视图中的配置文件名称指定为表头值。我希望能够消除混乱。 –