Hi I just want to start by saying I'm very new to LINQ and .NET. I am trying to grab a set of data using a linq query and populate the data as HTML table headers inside my listview. I can't hard code the headers since the headers are different for each organization I run the query on.
The following is an example of a query where im getting all the profile names for an organization and I would like to have each profile as a table header in my listview:
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);
and this is what my List view looks like in the presentation page:
<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"开发者_Python百科>
<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>
As you guys can see I'm currently hard coding the table headers in the but this is not what is required and I would like to be able to make the headers dynamic. Can someone please help me figure this issue out? If it is not possible to dynamically create headers in list view is there an alternative solution to this? Your help is greatly appreciated. Thanks in advance!
You can data bind the layout template of list view, which I have done but thats probably slightly more complex if you are relatively new.
How about separating the header from the list view that you are using. Use the list view for binding the items only and have a literal control write the header separately. You can use css to position them accordingly.
精彩评论