GridView 始终在上面
来源:互联网 发布:vb usercontrol控件 编辑:程序博客网 时间:2024/05/01 12:04
Introduction: Recently, I was working on a project that required that certain control always stay at the top of the page even if the user scrolls down the page. In this article I will demonstrate how to keep the GridView control at the top of the page using JavaScript. Scrolling Code: I got this neat scrolling code from the website known as codepunk. You can check out the original article at this link. The author did a very good job in explaining the concepts behind scrolling. Let’s check out the JavaScript code: function scrollingDetector(){ if (navigator.appName == "Microsoft Internet Explorer") { if(!document.documentElement.scrollTop) document.getElementById("myDiv").style.top = document.body.scrollTop; else document.getElementById("myDiv").style.top = document.documentElement.scrollTop; } else{ document.getElementById("myDiv").style.top = window.pageYOffset + "px"; } } The scrollingDetector method is used to assign the coordinates to the Div control with the ID is “myDiv”. The Div control contains the GridView control. The line navigator.appName checks that the browser type of the user. This check is made because different browsers use different properties to interact with the control. The above script will return you the position of the scroll bar. But, we need to call it repeatedly so the Div can change its position. For this reason I have created a new method called startScrollingDetector(). This method calls the JavaScript function setInterval which in turns call a any method at regular intervals. In the code below the function scrollingDetector() is called repeatedly after every 5 seconds. function startScrollingDetector() { setInterval("scrollingDetector()",5000); } The GridView Code: The GridView HTML code is pretty simple, as all you need to do is to place the GridView inside the “myDiv” control. <div id="myDiv" style="position:absolute; top:100px; right:100px;" > <asp:GridView ID="GridView1" runat="server" CellPadding="4" Font-Names="Verdana" ForeColor="#333333" GridLines="None"> <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#FFFBD6" ForeColor="#333333" /> <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /> <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> </div> You can check out the animation effect below. Please keep in mind that for animation effect I have decreased the interval to one second instead of five seconds.
- GridView 始终在上面
- 视图始终在最上面
- 怎样在Java Applet中实现子窗口始终显示在主窗口上面
- 窗口始终浮在上面的图钉按钮示例程序(详细编程)
- qt 第一个窗口全屏,第二个窗口是个对话框,要始终显示在第一个全屏窗口上面
- div始终在底端
- 始终在最下面
- 在使用 GridView的时候,有时需要多选上面显示的类容,比如批量删除上面显示的图片,批量上传图片等。
- android Button 始终在底端
- css 让页脚始终在底部
- 窗体始终在最前面
- 始终在路上--- 工作小结
- <footer>始终在页面底部
- div在flash上面
- 燕子在上面飞来飞去
- Fragment在Activity上面
- ListView上面是GridView,GridView显示不全的问题
- 如何使窗口始终在最前方?
- 工作流管理系统-分类与发展趋势及开发新系统目标、方向
- 总理这一跤,摔得惊天动地
- C++中的预处理
- 网页变为灰色
- 外报评论:中国式总理,想学学不来
- GridView 始终在上面
- 工作流管理系统-引擎调度需求
- 利用ajax.dll进行Ajax的开发
- 正确获取硬盘序列号源码
- 找房子
- 工作流管理系统-软件架构设计
- 全国哀悼日期间将网站风格变为黑白
- 检验密码强度的代码
- 立春