The GridView that the JS realizes is the table Head fixed table body has the scroll bar and can scroll

Source: Internet
Author: User

  Implementation of the GridView, the header is fixed, the table body has scrollbars and can be scrolled, here is a good example, I hope to help you.

  Code as follows: <%@ Page language= "C #" autoeventwireup= "true"%>    <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">    <script runat=" "Server" > ///calculation data can be obtained from the data to see   ICollection CreateDataSource ()   {   System.Data.DataTable dt = new System.Data.DataTable ();  System.Data.DataRow dr;  dt. Columns.Add (New System.Data.DataColumn ("Student Class", typeof (System.String));  dt. Columns.Add (New System.Data.DataColumn ("Student Name", typeof (System.String));  dt. Columns.Add (New System.Data.DataColumn ("language", typeof (System.Decimal));  dt. Columns.Add (New System.Data.DataColumn ("Mathematics", typeof (System.Decimal));  dt. Columns.Add (New System.Data.DataColumn ("English", typeof (System.Decimal));  dt. Columns.Add (New System.Data.DataColumn ("Computer", typeof (System.Decimal));    for (int i = 0; i < i++)   {  System.Random rd = new System.Random (EnviroNment. TickCount * i);;  dr = dt. NewRow ();  dr[0] = "Class" + i.tostring ();  dr[1] = "Test" + i.tostring ();  dr[2] = System.Math.Round (rd. Nextdouble () * 2);  dr[3] = System.Math.Round (rd. Nextdouble () * 2);  dr[4] = System.Math.Round (rd. Nextdouble () * 2);  dr[5] = System.Math.Round (rd. Nextdouble () * 2);  dt. Rows.Add (DR); }  System.Data.DataView dv = new System.Data.DataView (DT);  return dv; }    protected void Page_Load (object sender, EventArgs e)   {  if (! IsPostBack)   {  GridView1.Attributes.Add ("style", "table-layout:fixed");  Gridview1.datasource = CreateDataSource ();  gridview1.databind (); } }    </script>    <script Type= "Text/javascript" >  function S () {  var t = document.getElementById ("<%=GridView1.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  </script>    <html xmlns= "http://www.w3.org/1999/xhtml" >  <head>  <title> to create a table head fix, Table-scrollable gridview</title>  </head>  <body>  <form id= "Form1" runat= "Server" >   <table>  <tr>  <td>  <div id= "a" >  </div>  <div Style = "Overflow-y: scroll; height:200px ">  <asp:gridview id=" GridView1 "runat=" Server "font-size=" 12px "backcolor=" #FFFFFF "  Gridlines= "Both" cellpadding= "4" width= "560" >  <headerstyle backcolor= "#EDEDED" height= "26px"/>  </asp:GridView>  </div>  </td>  </tr>  </table>  </form >  </body>  </html>   

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.