Click here to Skip to main content
Click here to Skip to main content

Create a scrollable Gridview in asp.net 2.0

, 17 Oct 2006
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Xianhui Meng
Web Developer
China China
No Biography provided

Comments and Discussions

 
QuestionCode not working in Firefox PinmemberSunnyonfire24-Nov-11 3:43 
Generalnot working for me.. Pinmembermayur_mungi3-Jan-10 3:44 
GeneralMy vote of 1 Pinmember_ShreekUMAr_18-Nov-09 1:47 
GeneralOnly works with One Grid per Page Pinmemberrpeters7420-Mar-09 4:12 
GeneralRe: Only works with One Grid per Page [modified] Pinmemberrpeters7420-Mar-09 5:31 
Generalexcellent... but has a bug when use Themes Pinmemberjose garcia4-Jan-08 12:00 
GeneralJust a note on cloning w/ controls. PinmemberXorcist29-Nov-07 7:57 
GeneralExcellent! Could have used this for some time now. Pinmemberlotsoffear21-Nov-07 6:12 
QuestionHow about overflow: scroll instead of overflow-y? Pinmembercheepau20-Sep-07 18:11 
QuestionHow about fixed column headers? Pinmemberjmsteward12-Sep-07 8:59 
AnswerRe: How about fixed column headers? PinmemberSonal_0524-Mar-08 20:31 
QuestionCool!... but what about styles? Pinmemberandrez1027-Aug-07 11:26 
QuestionIt WORKS! How about a fixed footer? PinmemberGMartinTX17-Apr-07 11:31 
AnswerRe: It WORKS! How about a fixed footer? PinmemberGMartinTX17-Apr-07 12:13 
GeneralDoesn't work on sorting PinmemberUmesh_Soni27-Dec-06 19:17 
GeneralRe: Doesn't work on sorting Pinmembertopdrog17-Jun-07 13:21 
QuestionDoesn't work in firefox :( PinmemberGökmen BULUT13-Nov-06 23:49 
AnswerRe: Doesn't work in firefox :( Pinmemberlotsoffear21-Nov-07 6:04 
Generalworks fine as soon as I put change in the correct place great job thanks Pinmemberlennys3-Nov-06 12:35 
Generaltried your suggestion still fails Pinmemberlennys3-Nov-06 11:43 
Generaldoesn't work for me Pinmemberkunalagrawal20-Oct-06 10:07 
AnswerRe: doesn't work for me PinmemberXianhui Meng20-Oct-06 17:45 
GeneralRe: doesn't work for me Pinmemberkunalagrawal23-Oct-06 8:30 
GeneralRe: doesn't work for me PinmemberSasha Shipka20-Nov-06 3:05 
GeneralRe: doesn't work for me Pinmemberjason2k28-Oct-06 16:33 
GeneralRe: doesn't work for me Pinmemberjason2k28-Oct-06 16:38 
GeneralRe: doesn't work for me Pinmemberlovelylive10-Nov-06 19:34 
AnswerRe: doesn't work for me Pinmemberjason2k10-Nov-06 23:49 
GeneralRe: doesn't work for me Pinmemberlovelylive11-Nov-06 2:09 
GeneralRe: doesn't work for me Pinmemberjason2k11-Nov-06 2:20 
GeneralRe: doesn't work for me Pinmemberlovelylive11-Nov-06 3:25 
GeneralRe: doesn't work for me Pinmemberjason2k11-Nov-06 7:36 
GeneralCan you help me on MAC IE 5.2 [modified] Pinmemberkindestman24-Sep-08 8:19 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 17 Oct 2006
Article Copyright 2006 by Xianhui Meng
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid