Click here to Skip to main content
15,881,882 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 131.9K   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

 
QuestionCode not working in Firefox Pin
Sunnyonfire24-Nov-11 2:43
Sunnyonfire24-Nov-11 2:43 
Generalnot working for me.. Pin
mayur_mungi3-Jan-10 2:44
mayur_mungi3-Jan-10 2:44 
GeneralMy vote of 1 Pin
Shreekumar S18-Nov-09 0:47
professionalShreekumar S18-Nov-09 0:47 
GeneralOnly works with One Grid per Page Pin
rpeters7420-Mar-09 3:12
rpeters7420-Mar-09 3:12 
GeneralRe: Only works with One Grid per Page [modified] Pin
rpeters7420-Mar-09 4:31
rpeters7420-Mar-09 4:31 
Generalexcellent... but has a bug when use Themes Pin
jose garcia4-Jan-08 11:00
jose garcia4-Jan-08 11:00 
I use your control and works excellent... but when the page uses Themes, an error is generated

"La colección de controles no puede modificarse porque el control contiene bloques de código (por ej. <% ... %>)."
GeneralJust a note on cloning w/ controls. Pin
Xorcist29-Nov-07 6:57
Xorcist29-Nov-07 6:57 
GeneralExcellent! Could have used this for some time now. Pin
lotsoffear21-Nov-07 5:12
lotsoffear21-Nov-07 5:12 
QuestionHow about overflow: scroll instead of overflow-y? Pin
cheepau20-Sep-07 17:11
cheepau20-Sep-07 17:11 
QuestionHow about fixed column headers? Pin
jmsteward12-Sep-07 7:59
jmsteward12-Sep-07 7:59 
AnswerRe: How about fixed column headers? Pin
Sonal_0524-Mar-08 19:31
Sonal_0524-Mar-08 19:31 
QuestionCool!... but what about styles? Pin
andrez1027-Aug-07 10:26
andrez1027-Aug-07 10:26 
QuestionIt WORKS! How about a fixed footer? Pin
gmartinnc17-Apr-07 10:31
gmartinnc17-Apr-07 10:31 
AnswerRe: It WORKS! How about a fixed footer? Pin
gmartinnc17-Apr-07 11:13
gmartinnc17-Apr-07 11:13 
GeneralDoesn't work on sorting Pin
Umesh_Soni27-Dec-06 18:17
Umesh_Soni27-Dec-06 18:17 
GeneralRe: Doesn't work on sorting Pin
topdrog17-Jun-07 12:21
topdrog17-Jun-07 12:21 
QuestionDoesn't work in firefox :( Pin
Gökmen BULUT13-Nov-06 22:49
Gökmen BULUT13-Nov-06 22:49 
AnswerRe: Doesn't work in firefox :( Pin
lotsoffear21-Nov-07 5:04
lotsoffear21-Nov-07 5:04 
Generalworks fine as soon as I put change in the correct place great job thanks Pin
lennys3-Nov-06 11:35
lennys3-Nov-06 11:35 
Generaltried your suggestion still fails Pin
lennys3-Nov-06 10:43
lennys3-Nov-06 10:43 
Generaldoesn't work for me Pin
kunalagrawal20-Oct-06 9:07
kunalagrawal20-Oct-06 9:07 
AnswerRe: doesn't work for me Pin
Xianhui Meng20-Oct-06 16:45
Xianhui Meng20-Oct-06 16:45 
GeneralRe: doesn't work for me Pin
kunalagrawal23-Oct-06 7:30
kunalagrawal23-Oct-06 7:30 
GeneralRe: doesn't work for me Pin
Sasha Shipka20-Nov-06 2:05
Sasha Shipka20-Nov-06 2:05 
GeneralRe: doesn't work for me Pin
jason2k28-Oct-06 15:33
jason2k28-Oct-06 15:33 

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.