[英]How to Loop through linq query results and add result to Html table header in listview
嗨,我只想首先說我對 LINQ 和 .NET 很陌生。 我正在嘗試使用 linq 查詢獲取一組數據,並將數據填充為我的列表視圖中的 HTML 表標題。 我無法對標題進行硬編碼,因為我運行查詢的每個組織的標題都不同。
以下是一個查詢示例,其中我獲取組織的所有配置文件名稱,我希望在我的列表視圖中將每個配置文件作為表 header:
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>
正如你們所看到的,我目前正在對表格標題進行硬編碼,但這不是必需的,我希望能夠使標題動態化。 有人可以幫我解決這個問題嗎? 如果無法在列表視圖中動態創建標題,是否有替代解決方案? 非常感謝您的幫助。 提前致謝!
您可以數據綁定列表視圖的布局模板,我已經完成了,但如果您相對較新,那可能會稍微復雜一些。
如何將 header 從您正在使用的列表視圖中分離出來。 使用列表視圖僅綁定項目並使用文字控件單獨編寫 header。 您可以相應地使用 css 到 position 它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.