Click here to Skip to main content
15,904,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Freeze grid column and header in web application
Posted

1 solution

Hi,

A. For freezing Headers:
Step 1: Create a CSS class

.HeaderFreeze  
{  
position:relative ;   
top:expression(this.offsetParent.scrollTop);  
z-index: 10;  
}   

Step 2: Set Gridview’s HeaderStyle CssClass as follows
CssClass="HeaderFreeze"


B. For freezing Columns:
Step 1:   Add locked Css:
td.locked, th.locked 
{
  position:relative;    
  left:expression ((this.parentElement.parentElement.parentElement.parentElement.scrollLeft-2)+'px');
}   

Step 2:   In RowDataBound event add css to GridView cell something like:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].CssClass = "locked";
        }
    }
 
Share this answer
 
v2
Comments
chirprit 30-Jun-10 6:50am    
Reason for my vote of 1
Not working properly -->
VenuKalyan 25-Nov-11 0:42am    
Pls give code for .net 1.1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900