Freeze Pane in GridView

4. July 2009

Searching around the internet for how to do a freeze pane with a gridview like in excel was a bit tough. I know there were some example out there but all were different (which is fine) so I wanted to post another way you can do it without complicated CSS.  The concept behind this is to have a table with 2 columns and the one column have a fixed width with a div that has an overflow to it with scrolling.  This example only has a freeze like effect for horizontal scrolling. So this freeze the first two columns of the gridview.  A screenshot below is the example of the code.

 

Before posting the code here is a bit more on how this is accomplished. It actually has two gridviews that are bound to the same dataset.  So in a sense...is this the most efficient way..probably not. Then again the dataset is already in memory so the performance hit may not be too much.  The only other thing I can think to do is create two seperate datasets then fill them with the columns needed from the source dataset.  To me, this may cause more work because now you have to fill two extra datasets instead of just using one.  Plus, with the one dataset you can use the same DataKeyNames for both gridviews so you won't be hard to keep track of the key from each gridview. 

Ok so here is the code that makes this happen.  I will put so more notes at the bottom.  This has been testing on my box in IE7, Firefox 3.0.7 and Safari 3.2.1.

FreezPane.aspx.cs

FreezePane.aspx - this may show up horrible because the code may be too wide for it

Ok so instead of using the style tags for the gridview I has to explicitly style each template field for the HeaderStyle and ItemStyle-Wrap.  I had to do this because that is how it worked properly in IE7.  If I just did the RowStyle, AlternatingRowStyle, HeaderStyle on the gridview itself it worked how it was supposed to in Firefox and Safari, but not IE7. Not sure why this is, but whatever, maybe I missed something.

Again, this produces a freeze pane like effect with a gridview, but it's actually two gridviews sharing the same dataset but only binding to columns necessary for each one from the dataset.  Here is the XML file for the mock data:

I probably just should of zipped up all the code huh...but what fun is that!  Ok any suggestions on how to make this better let me know, but with this concept it provides a way to use gridviews so the data can be dynamic without using any CSS really.
 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

ASP.NET

Comments

bhaskr
11/3/2009 12:27:25 PM #
Dude this is not a solution but a workaround.
You are taking two different grids ot render the fix columns.
11/3/2009 5:00:39 PM #
Bhaskr, I agree it is not a full solution. From my research all solutions were IE specific or browser specific.  I can see how you consider it a work around, but I guess that's what's good about coding, we all have different solutions.  To be honest, I wish I could have used Silverlight for this solution at the time...would have been accomplished in 10 seconds.  Thanks for the feedback and if you find a better one to go across browsers I'd be more than happy to know and I will update the post to add the link. Take care
Uday
1/15/2010 8:32:29 AM #
Freezing HeaderRow as well as Columns not working.
Simply u r wastin others time.

if interested send working code to me,
otherwise don't put all this rubbish things on web...


1/15/2010 4:56:10 PM #
Uday,

I'm not freezing the HeaderRow and I'm not freezing columns. From what I researched nobody has a full blown solution to work across browsers. This is simply binding two gridviews and putting one of the gridviews in an div with overflow enabled.  As bhaskr mentioned in the first comment, it is a work around. I'd be more than happy to update this post if somebody can provide a real solution that works across browsers.

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading