Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed Header Grid View ASP.NET

I gone through lots of examples for fixed header grid view, and tried few options using div and java scripts. the one i didnot work from the example, is there anything i miss here.

 CSS 
.gridViewHeader
{
     background-color:Navy;
    color:blue;
    font-size:12px;
    font-weight:bold;
    position:relative;
    z-index:10;
   top:expression(<%= gv.HeaderRow %>.offsetParent.scrollTop-2);
}

design source
<table>
<tr>
            <td>
                &nbsp;
            </td>
        </tr>
    </table>
    <div>
        <asp:GridView ID="gv" runat="server" CellPadding="4" PageSize="50" RowHeaderColumn="True"
            AllowPaging="True" BackColor="White" BorderColor="#3366CC" BorderStyle="None"
            BorderWidth="1px" CssClass="gridViewHeader">
            <PagerSettings Mode="NumericFirstLast" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" VerticalAlign="Middle" />
            <RowStyle BackColor="White" ForeColor="#003399" BorderStyle="Inset" HorizontalAlign="Center"
                VerticalAlign="Middle" Wrap="False" />
            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        </asp:GridView>
    </div>
        <asp:HiddenField ID="hiddenfield1" runat="server"  />
    </asp:Content>
like image 699
Fun Living Avatar asked Sep 11 '26 07:09

Fun Living


2 Answers

you can use

<HeaderStyle CssClass="gridViewHeader" />

For your sample

<asp:GridView ID="gv" runat="server" CellPadding="4" PageSize="50" RowHeaderColumn="True"
            AllowPaging="True" BackColor="White" BorderColor="#3366CC" BorderStyle="None"
            BorderWidth="1px" >

            <HeaderStyle CssClass="gridViewHeader" />

            <PagerSettings Mode="NumericFirstLast" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" VerticalAlign="Middle" />
            <RowStyle BackColor="White" ForeColor="#003399" BorderStyle="Inset" HorizontalAlign="Center"
                VerticalAlign="Middle" Wrap="False" />
            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        </asp:GridView>
like image 176
Aghilas Yakoub Avatar answered Sep 13 '26 19:09

Aghilas Yakoub


This CSS will fix your problem:

.GVFixedHeader { font-weight:bold; background-color: Green; position:relative; 
             top:expression(this.parentNode.parentNode.parentNode.scrollTop-1);}
like image 41
Chaitali Avatar answered Sep 13 '26 19:09

Chaitali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!