I have a ListView within a div. The div has a maximum height of 240px, therefore when the ListView reaches a certain amount of rows the div will scroll.
I would like the thead row within the ListView to stay at the top of the div at all times. I have played around with this for a while now and looked at the following http://blogs.interfacett.com/dan-wahlins-blog2007-8-2-video-using-the-new-asp-net-listview-control-html-and-freezing-the-header , but sadly I have had no luck. I followed the video tutorial to the letter but (as the only comment on the page says) it isn't working for me.
I'm using, and would prefer to keep using, asp.net 3.5.
If possible I would like the solution to be a pure CSS solution, but if JavaScript is necessary then so be it.
Here is my html code
<html code>
<asp:ListView ID="UserListView" runat="server" DataSourceID="ListViewDataSource"
ItemPlaceholderID="UserListViewContent" EnableModelValidation="True" DataKeyNames="ID,Reference,Type"
OnPreRender="UserListView_PreRender" OnSelectedIndexChanged="UserListView_SelectedIndexChanged">
<LayoutTemplate>
<div id="List" class="ListViewStyle">
<table width="600px" cellspacing="0" cellpadding="0">
<thead>
<tr class="tableHeaderRow" style="height: 24px; text-align:left" >
<th style="width: 45px">
<asp:LinkButton ID="LinkButton1" runat="server" Text="ID" CommandName="Sort" CommandArgument="ID"
CausesValidation="false"></asp:LinkButton>
</th>
<th style="width: 45px">
<asp:LinkButton ID="LinkButton2" runat="server" Text="User" CommandName="Sort" CommandArgument="Reference"
CausesValidation="false"></asp:LinkButton>
</th>
<th style="width: 75px">
<asp:LinkButton ID="LinkButton3" runat="server" Text="Status" CommandName="Sort" CommandArgument="Status"
CausesValidation="false"></asp:LinkButton>
</th>
<th style="width: 100px">
<asp:LinkButton ID="LinkButton4" runat="server" Text="Level" CommandName="Sort" CommandArgument="Type"
CausesValidation="false"></asp:LinkButton>
</th>
<th style="width: 130px">
<asp:LinkButton ID="LinkButton5" runat="server" Text="First Names" CommandName="Sort" CommandArgument="FirstNames"
CausesValidation="false"></asp:LinkButton>
</th>
<th style="width: 125px">
<asp:LinkButton ID="LinkButton6" runat="server" Text="Surname" CommandName="Sort" CommandArgument="Surname"
CausesValidation="false"></asp:LinkButton>
</th>
<th style="width: 80px">
</th>
</tr>
</thead>
<tbody runat="server" id="UserListViewContent">
</tbody>
</table>
</div>
</LayoutTemplate>
<AlternatingItemTemplate>
<tr class="altRowStyle" style="height: 24px">
<td style="width: 45px; overflow:hidden;">
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td style="width: 45px; overflow:hidden;">
<asp:Label ID="ReferenceLabel" runat="server" Text='<%# Eval("Reference") %>' />
</td>
<td style="width: 75px; overflow:hidden;">
<asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>' />
</td>
<td style="width: 100px; overflow:hidden;">
<asp:Label ID="TypeLabel" runat="server" Text='<%# Eval("Type") %>' />
</td>
<td style="width: 130px; overflow:hidden;">
<asp:Label ID="FirstNamesLabel" runat="server" Text='<%# Eval("FirstNames") %>' />
</td>
<td style="width: 125px; overflow:hidden;">
<asp:Label ID="SurnameLabel" runat="server" Text='<%# Eval("Surname") %>' />
</td>
<td style="width: 80px; overflow:hidden;">
<asp:Button ID="ItemTemplateButton" runat="server" Text="Select" CssClass="standardButton"
CommandName="Select"></asp:Button>
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr class="rowStyle" style="height: 24px">
<td style="width: 45px; overflow:hidden;">
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td style="width: 45px; overflow:hidden;">
<asp:Label ID="ReferenceLabel" runat="server" Text='<%# Eval("Reference") %>' />
</td>
<td style="width: 75px; overflow:hidden;">
<asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>' />
</td>
<td style="width: 100px; overflow:hidden;">
<asp:Label ID="TypeLabel" runat="server" Text='<%# Eval("Type") %>' />
</td>
<td style="width: 130px; overflow:hidden;">
<asp:Label ID="FirstNamesLabel" runat="server" Text='<%# Eval("FirstNames") %>' />
</td>
<td style="width: 125px; overflow:hidden;">
<asp:Label ID="SurnameLabel" runat="server" Text='<%# Eval("Surname") %>' />
</td>
<td style="width: 80px; overflow:hidden;">
<asp:Button ID="ItemTemplateButton" runat="server" Text="Select" CssClass="standardButton"
CommandName="Select"></asp:Button>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr class="selectedRowStyle" style="height: 24px">
<td style="width: 45px; overflow:hidden;">
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td style="width: 45px; overflow:hidden;">
<asp:Label ID="ReferenceLabel" runat="server" Text='<%# Eval("Reference") %>' />
</td>
<td style="width: 75px; overflow:hidden;">
<asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>' />
</td>
<td style="width: 100px; overflow:hidden;">
<asp:Label ID="TypeLabel" runat="server" Text='<%# Eval("Type") %>' />
</td>
<td style="width: 130px; overflow:hidden;">
<asp:Label ID="FirstNamesLabel" runat="server" Text='<%# Eval("FirstNames") %>' />
</td>
<td style="width: 125px; overflow:hidden;">
<asp:Label ID="SurnameLabel" runat="server" Text='<%# Eval("Surname") %>' />
</td>
<td style="width: 80px; overflow:hidden;">
<asp:Button ID="ItemTemplateButton" runat="server" Text="Select" CssClass="standardButton"
CommandName="Select"></asp:Button>
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
And here's the Css
<css code>
.ListViewStyle
{
width: 620px;
max-height: 240px;
height: expression( scrollHeight < 240 ? 'auto' : '240px' );
overflow: auto;
border-left: 1px solid #EEF5FE;
}
.ListViewStyle th
{
position:relative;
}
Any and all help will be very much appreciated.
Cheers