Wednesday, February 9, 2011

Freeze the columns in Gridview

Sometimes you need a way in which you don't want end user to edit some columns of gridview. There is no direct way for this. But you can achieve this with the help of CSS functionality.

STEP 1: Add the Following CSS class to the .aspx file
<style type="CSS/Text">
text-align: left;
cursor: default;

STEP 2: Set the CSSClass property of the cells in the GridView RowDatabound event as shown below.

protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
e.Row.Cells[1].CssClass = "freezecolumn";
This way you can freeze the column or you can say non-editable column in gridview.

Happy Coding!!

No comments:

Post a Comment