Freeze the columns in ASP.NEt Gridview
In case of datagrids with high number of columns, the datagrids can be made scrollable by placing it with in a div tag.
However , when the scrolling is enabled, in most business scenarios, in any row, all the data in the other column refers to one or two main columns often the leftmost column.
In this case when we scroll to the rightmost end, we lose the context. It would be nice if we could have a feature like the ones that we have in Microsoft Exce, where we can freeze certain columns.
Here is a simple way to do that.
The idea is to have the left property of each of the cells in that column fixed.
STEP 1: Add the Following CSS class to the .aspx file
td.freezepane{
text-align: left;
border-width:0;
background-color:White;
position:relative;
cursor: default;
left:inherit;
}
STEP 2: Set the CSSClass property of the cells in the GridView RowDatabound event.
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{e.Row.Cells[1].CssClass = "locked";
}
And Thats it... the first column will remain freezed.
Comments
Anonymous
January 03, 2009
PingBack from http://www.codedstyle.com/freeze-the-columns-in-aspnet-gridview/Anonymous
July 21, 2010
Can you put a more a working exapmple since it is not working for me ThanksAnonymous
March 28, 2013
file:///F:/mitul/GridViewScroll/WebForm.htmAnonymous
March 28, 2013
stackoverflow.com/.../asp-net-horizontal-scroll-fro-gridviewAnonymous
January 06, 2014
You should be banded to post garbage like this.