[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

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
0
Amitava_Mukherjee
Asked:
Amitava_Mukherjee
  • 3
  • 3
1 Solution
 
rahkimfCommented:
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

0
 
Amitava_MukherjeeAuthor Commented:
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"
0
 
rahkimfCommented:
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Amitava_MukherjeeAuthor Commented:
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
0
 
rahkimfCommented:
Just to be sure...did you put your datagrid in the div like this -
<div id="tbl-container">
     <asp:GridView id="mygrid" OnItemDataBound="myGrid_ItemDataBound" ... />
</div>
0
 
Amitava_MukherjeeAuthor Commented:
Thanx
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now