Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Create a scrollable Gridview in asp.net 2.0

0.00/5 (No votes)
17 Oct 2006 1  
Using Javascript's cloneNode to create scrollable Gridview in asp.net 2.0

Sample Image - ScrollingGridView.gif

Introduction

  Using Javascript's cloneNode ,we can clone a table's header,so we can make a gridview to be scrollable.This method isn't set some long css.

  In asp.net 2.0's Page_Load event,we must add style for GridView, and this MUST for IE and Firefox can work!

  protected void Page_Load( object sender, EventArgs e )
  {
    if (!IsPostBack)
    {
      GridView1.Attributes.Add("style", "table-layout:fixed");
      GridView1.DataSource = CreateDataSource();
      GridView1.DataBind();
    }
  }

 Next,we must add some javascript for it:

function start()
{
 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 = start

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here