Jump to content
999ANDRE999

Fixar cabeçalho de gridview

Recommended Posts

999ANDRE999

Bom dia pessoal!

Tenho uma gridview com várias colunas e várias linhas. Quando faço scroll, a determinada altura, o header da grid desaparece e eu fico sem saber o que é cada campo da grid. Após alguma pesquisa descobri como fixar o header da grid, de forma a que quando faça scroll continue a saber o que é cada campo da minha grid, usando javascript:

function s() {
            var t = document.getElementById("<%=GridView_project.ClientID%>");
            var t2 = t.cloneNode(true)
            for (i = t2.rows.length - 1; i > 0; i--)
                t2.deleteRow(i)
            t.deleteRow(0)
            a.appendChild(t2)
        }
        window.onload = s
<asp:Panel ID="Panel_gridview_project" runat="server" HorizontalAlign="Center">
        <div id="a" style="width: 100%">
        </div>
        <div style="overflow-y: scroll; overflow-y: scroll; height: 500px; width: 100%">
            <asp:GridView ID="GridView_project" runat="server" HorizontalAlign="Center" BackColor="White"
                BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
                AutoGenerateDeleteButton="True" ShowFooter="True" AutoGenerateColumns="False"
                OnRowDeleting="gridview_RowDeleting" OnRowDataBound="Grid_RowDataBound" DataKeyNames="project"
                Font-Size="Smaller" OnRowCreated="grvMergeHeader_RowCreated" EmptyDataText="No data" 
                ShowHeaderWhenEmpty="True">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:TemplateField HeaderText="Road map of new products">
                        <HeaderTemplate>
                            Road map of new products<br />
                            <asp:DropDownList ID="DropDownList0" runat="server" AppendDataBoundItems="true" ondblclick="this.size=1;"
                                onfocusout="this.size=1;" onmousedown="this.size=5;">
                            </asp:DropDownList>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label0" Text='<%# Eval("project") %>' runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Client">
                        <HeaderTemplate>
                            Client<br />
                            <asp:DropDownList ID="DropDownList_client" runat="server" AppendDataBoundItems="true"
                                ondblclick="this.size=1;" onfocusout="this.size=1;" onmousedown="this.size=5;">
                            </asp:DropDownList>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label75" runat="server" Text='<%# Eval("client") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                  
                  
                  
                  .....
                  
                  
                  
                  </Columns>
                <FooterStyle BackColor="#565656" />
                <HeaderStyle BackColor="#565656" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
                <PagerSettings Mode="NextPrevious" />
                <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Center" />
                <RowStyle BackColor="White" />
                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#FBFBF2" />
                <SortedAscendingHeaderStyle BackColor="#848384" />
                <SortedDescendingCellStyle BackColor="#EAEAD3" />
                <SortedDescendingHeaderStyle BackColor="#575357" />
                <SortedAscendingCellStyle BackColor="#FBFBF2" />
                <SortedAscendingHeaderStyle BackColor="#848384" />
                <SortedDescendingCellStyle BackColor="#EAEAD3" />
                <SortedDescendingHeaderStyle BackColor="#575357" />
            </asp:GridView>
        </div>
    </asp:Panel>

O problema é que as células da grid alargam ou estreitam o seu tamanho de acordo com a quantidade de informação contida em determinada célula, e a largura das células do header fica sempre igual, ficando desalinhada com o resto da tabela. Um exemplo:
| header1 |     header2     |      header3   | header 4|
|cel1 |   cel2   |             cel3             |       cel4    |
|cel1 |   cel2   |             cel3             |       cel4    |
|cel1 |   cel2   |             cel3             |       cel4    |
|cel1 |   cel2   |             cel3             |       cel4    |

Alguém me sabe dizer como manter a largura das células do header iguais à largura das células da tabela?

Obrigado! :thumbsup:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.