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

text-align: left;
cursor: default;


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 (5)

  1. Rajeshwari says:

    Can you put a more a working exapmple since it is not working for me


  2. not says:


  3. Igor says:

    You should be banded to post garbage like this.

Skip to main content