'how to fix header of table with repeater controll with vertical scroll?

I have to fix header of table when i scroll down i want to see column header till the end of records. i made this but i am facing a problem. i fetch data from database that's a dynamic data so when i display that in table the layout gets odd. because if there is a column with more than 1000 words that will change its width while i mention table cell width with percentage. how i can solve this problem that header remain on the top and the layout will not be disturbed what ever data is. i do not want to use jQuery

.gridScrollDiv
{
border:1px solid #CCCCCC;
height: 500px;
overflow: scroll;
overflow-x: hidden;
}

<div class="gridScrollDiv">
    <table id="tblData" class="grid" style="width: 100%;" cellpadding="0">
        <thead style="position:absolute;">
            <tr>
                <th style="width:40%;">
                    Code
                </th>
                <th style="width:40%;">
                    Description
                </th>
                <th style="width:20%;">
                    Date
                </th>
            </tr>
        </thead>
        <tbody>
            <asp:Repeater ID="rptLoation" runat="server">
                <ItemTemplate>
                    <tr>
                        <td style="width:40%; word-wrap:breake-word;">
                            <%# DataBinder.Eval(Container.DataItem, "Code")%>
                        </td>
                        <td style="width:40%; word-wrap:breake-word;">
                            <%# DataBinder.Eval(Container.DataItem, "Description")%>
                        </td>
                        <td style="width:20%; word-wrap:breake-word;">
                            <%# DataBinder.Eval(Container.DataItem, "RegistrationDate")%>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </tbody>
    </table>
</div>


Solution 1:[1]

you can use code like below. I have modified css.

.gridScrollDiv
    {
        border: 1px solid #CCCCCC;
        height: 500px;
        overflow-y: scroll;
    }

taking out the header from the repeater.

<table style="width: 100%;">
    <tr style="font-weight: bold;">
        <tr>
            <td style="width: 40%; text-align: left">
                Code
            </td>
            <td style="width: 40%; text-align: left">
                Description
            </td>
            <td style="width: 20%; text-align: left">
                Date
            </td>
        </tr>
</table>
<div class="gridScrollDiv">
    <asp:Repeater ID="rptLoation" runat="server">
        <HeaderTemplate>
            <table style="width: 100%;">
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td style="width: 40%; word-wrap: breake-word;">
                   <div style="width: 350px; overflow-x: scroll;"> 
                   <%# DataBinder.Eval(Container.DataItem, "Code")%>
                   </div>
                </td>
                <td style="width: 40%; word-wrap: breake-word;">
                     <div style="width: 350px; overflow-x: scroll;">
                    <%# DataBinder.Eval(Container.DataItem, "Description")%>
                    </div>
                </td>
                <td style="width: 20%; word-wrap: breake-word;">
                    <div style="width: 350px; overflow-x: scroll;">
                    <%# DataBinder.Eval(Container.DataItem, "RegistrationDate")%>
                    </div>

                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
</div>

this might resolve your purpose....

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1