Click here to Skip to main content
15,892,697 members
Articles / Web Development / ASP.NET
Article

Create a scrollable Gridview in asp.net 2.0

Rate me:
Please Sign up or sign in to vote.
3.14/5 (13 votes)
17 Oct 2006 132K   1.2K   45   33
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!

C#
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:

JavaScript
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


Written By
Web Developer
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: doesn't work for me Pin
jason2k28-Oct-06 15:38
jason2k28-Oct-06 15:38 
GeneralRe: doesn't work for me Pin
lovelylive10-Nov-06 18:34
lovelylive10-Nov-06 18:34 
AnswerRe: doesn't work for me Pin
jason2k10-Nov-06 22:49
jason2k10-Nov-06 22:49 
GeneralRe: doesn't work for me Pin
lovelylive11-Nov-06 1:09
lovelylive11-Nov-06 1:09 
GeneralRe: doesn't work for me Pin
jason2k11-Nov-06 1:20
jason2k11-Nov-06 1:20 
GeneralRe: doesn't work for me Pin
lovelylive11-Nov-06 2:25
lovelylive11-Nov-06 2:25 
GeneralRe: doesn't work for me Pin
jason2k11-Nov-06 6:36
jason2k11-Nov-06 6:36 
GeneralCan you help me on MAC IE 5.2 [modified] Pin
kindestman24-Sep-08 7:19
kindestman24-Sep-08 7:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.