in

ASP.NET Weblogs

Datagrid Girl

Marcie, ASP.NET Datagrid Blogger Girl

Scrolling with a Datagrid in a DIV

Today I got the chance to make use of Jim Ross's excellent article, “Maintain Scroll Position in Any Page Element”.  It describes when using a scrollable Datagrid--one inside an overflow-auto DIV control--how to maintain the user's scroll position inside the DIV across postbacks, such as when a Select button is clicked.  It does this using IE behaviors, HTC files, which I hadn't used before, so that was fun, and it also solved my problem.

I also liked the ReadMe.txt that came with the sample downloaded code:  “The sample application is written in VB. If you only know how to read C#, stop whining and learn to read another language. It will be good for your soul, and your career.” :)

P.S. Jim also has a new article out about Datagrids and ViewState, check it out.

Comments

 

Anon said:

"stop whining and learn to read another language. It will be good for your soul, and your career.”

Could go both ways.
September 4, 2003 5:43 PM
 

Anon2 said:

Could go both ways for many people on dotnetweblogs
September 4, 2003 5:44 PM
 

Datagrid Girl said:

That's the whole point--BOTH C# and VB people should be able to read the other language, it just makes life so much simpler.
September 4, 2003 5:54 PM
 

Jesse Ezell said:

IMO, using a behavior for this is pretty lame, as is just hard coding it in your HTML every time and it isn't going to work outside of IE. Here is an improvement:

1. Create a custom web control class ScrollablePanel
2. override OnPreRender to register the onScroll script / onLoad script via RegisterClientScriptBlock
3. override CreateChildControls method and add your hidden field.
4. override your control's render method to output your custom DIV tag.
5. add ScrollPosition property
6. implement IPostBackDataHandler / LoadPostData.

Now you have a .NET control that you can reuse to your heart's content.
September 4, 2003 6:02 PM
 

Sam Gentile said:

> That's the whole point--BOTH C# and VB people should be able to read the other language, it just makes life so much simpler.

Well sort of. The whole point is that 90% of the syntax in *either* language is BCL or CLR stuff so the CLR language is irrelevant. I have been saying this for over 2 years now and people just don't want to get it. If you can read VB.NET you can read C# and vise versa because most of the code is BCL calls (like System.Console.WriteLine for instance). Its WriteLine no matter what the CLR language is. When people get to "Its the Runtime Stupid" and finally accept that, then they will get somewhere.
September 4, 2003 6:43 PM
 

Datagrid Girl said:

Hi Jesse, in my case using an IE behavior wasn't "lame", as it's for an IE-only application.
September 4, 2003 7:13 PM
 

Jesse Ezell said:

This just shows a difference in philosophies I guess. Generally, I spend my time building libraries, so I am always in code reuse mode. Here at the office, we have at least one assembly that is referenced in the majority of the projects we are working on. It contains utility classes such as this as well as other common web controls (such as listview and treeview) that aren't part of the .NET framework (another assembly is also reused in 90% of our projects which contains our custom authentication / profile / security classes). Although the first time around, the benefits aren't immediately realized, it saves quite a bit of time in the long run.

Anyway, you are still better off not using a behavior, even with an IE only application. First off, it takes about the same amount of work to do it either way (maybe 5 extra minutes of coding to create the control version). Secondly, using a behavior makes reuse of your scrollable div a pain (you can't package in a reusable dll). Third, if you have more than one scrollable grid in your application, you are going to be duplicating a lot of code (not to mention that you can use a scrollable panel for any scrollable content area, not just a grid). Fourth, even if THIS application was an IE only application, there is no gaurentee that your next project will be. And finally, as this functionality is pretty generic, not doing things right the first time around will only cause you extra work the second time around.

I guess everyone has a different oppinion on how important reuse is though... Some people like getting paid to write the same code over and over again :-). In any case, as I noted previously, this is all IMO. Everyone is free to disagree.
September 4, 2003 8:07 PM
 

Jim Ross said:

It's good to see that Marcie's taste in articles is as good as her taste in husbands. [grin].

I readily acknowledge the criticism against HTC's, but I also will point out that I specifically stated in the article that the htc could be a limitation.

Re: a "lame" approach and I should have created a custom web control, I fully agree that this kind of thing is an excellent candidate for a custom control. However, my purpose wasn't to write a treatise on web controls, but to show how to solve the scrolling problem. Now that the technique has been shown, I freely grant permission to anyone who wishes to incorporate it into a custom control and write an article that shows how to do it. But for myself, I have found that StrengthTechnologies excellent "SmartScroller" has already done that.
September 7, 2003 1:52 AM
 

Robert McLaws said:

Making it a custom control is not as easy as you might think. It's actually pretty darn complicated. At least it is if you want to break the header out of the table.
December 5, 2003 4:56 AM
 

Kathy Bungard said:

I'd like to see an article related to this subject - how to sort a dataGrid when headers exist outside of the dataGrid (with and without making a round trip back to the database).

Keep up the good work Marcie
March 2, 2004 2:07 PM
 

rakesh kumar said:

hi,
my problem is that size of the scroll bar is not increasing or decreasing with the increase in size of the table.kindly resolve this problem.
March 9, 2004 5:19 AM
 

chandrakumar said:


My Page Has Common Top Header
Under the Header dynamic message occurs
Whenever scroll the page
the top remains visible up to end of scroll
How?
July 28, 2004 8:25 AM

Leave a Comment

(required)  
(optional)
(required)  
Add