Link to home
Start Free TrialLog in
Avatar of Amitava_Mukherjee
Amitava_MukherjeeFlag for India

asked on

how to freeze left three columns of a datagridview in asp.net

I want to freeze left three columns of datagridview in asp.net. It is a readily available property in WinForm, but how to make it in asp.net? Please suggest.

Any javascript code snippet or  CSS code is also welcome.

Thanking you,
Soumen
Avatar of rahkimf
rahkimf

I know this will work in IE5+.  I havent tested in other browsers, but you should be able to modify.

There might be more elegant ways, but I use this method to lock the head or cols.

Be sure to put your datagrid in a div called <div id="tbl-container">
Also, be sure to add this to the grid properties - OnItemDataBound="myGrid_ItemDataBound"
//asp code behind
public void myGrid_ItemDataBound(Object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{				
     e.Item.Cells[0].Attributes.Add("class", "locked");
     e.Item.Cells[1].Attributes.Add("class", "locked");
     e.Item.Cells[2].Attributes.Add("class", "locked");
}
}
 
//style sheet
.locked 
{
position:relative;
cursor: default; 	
top: expression(document.getElementById("tbl-container").scrollTop-2); /* IE5+ only */
z-index: 20;
}
 
 
td.locked,  th.locked{
left: expression(document.getElementById("tbl-container").scrollLeft); /* IE5+ only */
position: relative;
z-index: 10;
}

Open in new window

Avatar of Amitava_Mukherjee

ASKER

left: expression(document.getElementById("tbl-container").scrollLeft);

this line generate error in CSS. Error returns "tbl-container is not a valid value for the list property"
Do you mean "tbl-container is not a valid value for the left property?"

My CSS in VS says that also.  But it still works.  Is the page not loading at all?
the page is loading and showing all the things without any error. but no effect of the css

I'd specified the the css in my seleted theme's css file
ASKER CERTIFIED SOLUTION
Avatar of rahkimf
rahkimf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx