純指令碼搞掂DataGrid表表頭不動,表身滾動

來源:互聯網
上載者:User

先看效果:

孟子以前也做過這事,不過他的方法前台後台都要弄,還是VB的(^-^),好像也不支援像我的自動產生列的DataGrid,所以還是自己動手,純指令碼搞掂,其實很簡單,就幾行:

        function ScrollDataGrid()
        {
            var tb = document.getElementById("tbHeader");
            var dg = document.getElementById("dgSearchResult");
            
            if(dg!= null)
            {    
                var dv = document.getElementById("dvBody");
                var th = dg.rows[0];
                for(var i = 0 ; i < th.cells.length;i++)
                    th.cells[i].width = th.cells[i].clientWidth;
                var tr = th.cloneNode(true);
                
                //tr.applyElement(tb);
                tb.createTHead();
                var tbh = tb.tHead;
                tbh.appendChild(tr);
                tr = tbh.rows[0];
                var td = tr.insertCell();
                td.style.width = 19;
                td.width = 19;
                td.innerHTML = tr.cells[0].innerHTML;
                th.style.display = 'none';
                if(dg.scrollHeight < 300 )
                    dv.style.height = dg.scrollHeight * 1 + 2;
                
                
            }

 

                <table width="100%" border="0" id="tbHeader" cellpadding="4" cellspacing="0">
                                        </table>
                                        <div style="OVERFLOW-Y: scroll; HEIGHT: 300px" id="dvBody">
                                            <asp:datagrid id="dgSearchResult" style="BORDER-COLLAPSE: collapse" runat="server" Width="100%" CellPadding="4" DataKeyField="編號" BorderWidth="1px" BorderStyle="Solid" BorderColor="RoyalBlue" GridLines="None">
                                                <SelectedItemStyle ForeColor="SlateGray"></SelectedItemStyle>
                                                <ItemStyle VerticalAlign="Middle"></ItemStyle>
                                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                                <Columns>
                                                    <asp:ButtonColumn Text="選擇" HeaderText="&lt;font face=webdings&gt;6&lt;/font&gt;" CommandName="Delete">
                                                        <HeaderStyle Wrap="False" Width="40px"></HeaderStyle>
                                                        <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
                                                        <FooterStyle Wrap="False"></FooterStyle>
                                                    </asp:ButtonColumn>
                                                </Columns>
                                            </asp:datagrid></div>

 

 

http://thinhunan.cnblogs.com/archive/2005/05/27/163704.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.