The table header does not move and the table body is scrolled. Abstract)

Source: Internet
Author: User
The table header does not move and the table body is scrolled.

First look at the effect:

Mencius has done this before, but his method is required in front-end and back-end. It is still VB (^-^). It does not seem to support the DataGrid like my auto-generated columns, therefore, it is very easy to implement scripts by yourself. Just a few lines:

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 = "No" Borderwidth = "1px" Borderstyle = "Solid" Bordercolor = "Maid" Gridlines = "NONE" >  
< Selecteditemstyle Forecolor = "Slategray" > </ Selecteditemstyle >  
< Itemstyle Verticalalign = "Middle" > </ Itemstyle >  
< Headerstyle Horizontalalign = "Center" > </ Headerstyle >  
< Columns >  
< ASP: buttoncolumn Text = "Select" 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 >  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.