|
Welcome,
Guest
|
ASP.NET PROGRAMS, ASP.NET DESIGN, ASP.NET CODE, ASP.NET TOOLS
ASP.NET combines Active Server Pages with the .NET Framework. This technology allows you to create dynamic web applications. ASP.NET pages work in all browsers. Best of all, ASP.NET lets you build web pages using less code than you need with classic ASP. If you’re using ASP.NET to build some applications for your website, you owe it to yourself to check out the articles in this section.
ASP.NET combines Active Server Pages with the .NET Framework. This technology allows you to create dynamic web applications. ASP.NET pages work in all browsers. Best of all, ASP.NET lets you build web pages using less code than you need with classic ASP. If you’re using ASP.NET to build some applications for your website, you owe it to yourself to check out the articles in this section.
|
TOPIC: Grid View with fixed header
Grid View with fixed header 12 Mar 2010 01:27 #303
|
Introduction
GridView Control of Asp.Net makes our task very simpler as comparison to HTML tables. But one problem which I always faced with GridView Control is of scrolling headers. I tried several forums and websites, but didn’t come up with good solution. In this article, I am trying to solve the problem of scrolling headers in Asp.net GridView control. This article will fulfill the following requirements.
Overview GridView doesn’t have the ability to scroll. But if the GridView contains the larger number of rows or columns (say more than 100 rows and 15 Columns), we want it to have scrollbars. Since, the Div control has the ability to scroll horizontally and vertically, therefore, to achieve scrolling in GridView we have to wrap the GridView in the Div control. It is the Div who actually scrolls, but it looks like that GridView is scrolling. Wrapping the GridView in a Div (say DataDiv) and making the DataDiv overflow property to auto solves the problem of scrolling in GridView, but one problem is that the header of the GridView also scrolls up while scrolling it vertically (this is because, the DataDiv is actually scrolling but not the GridView). To get the solution of this problem, put another Div (say HeaderDiv) above DataDiv. The next step is to create a new HTML table in HeaderDiv which will contain the new header for the GridView. This job will be done by a JavaScript function (say CreateGridHeader()). This JavaScript function also sets the HeaderDiv style as per the DataDiv and new HTML table style as per GridView style and also we will hide the original header of GridView. This function will be called every time after filling the GridView with data as well as on the Page Load. At this point we will have header (new HTML table) and GridView as different entities. Since, header and GridView both are different entities; therefore, one thing which is still left is how to scroll the header while scrolling the GridView horizontally. This job will be done by a JavaScript function (say Onscrollfnction ()) which will be executed at the scroll event of the DataDiv. This function will scroll the HeaderDiv along with the DataDiv while scrolling in horizontal direction. Objective The main objective behind the overall exercise is to create the new table (which contains the new header row) above the GridView with the similar style attributes of the original header and hides the original header of GridView. [bUsing the Code[/b] 1. The first thing we have to do is to put the GridView inside the Div tag and also define a Header Div which will contain the new Header as follows: <%--Div contains the new header of the GridView--%>Please note the following points in the above code.
function Onscrollfnction() This function will scroll the HeaderDiv along with the DataDiv while scrolling in horizontal direction. 3. The third step is to write a Javascript function CreateGridHeader(). This function will create a new header table for the GridView in HeaderDiv and hides the original header. This function also resolves the style issues between HeaderDiv and DataDiv. This function will be called every time after filling the GridView with data as well as on the Page Load function CreateGridHeader(DataDiv, GridView1, HeaderDiv) This function will take three parameters DataDiv, GridView, and HeaderDiv. This function needs to be called from the server side every time the Grid is filled with data and also on the Page Load. 4. The final step is to fill the GridView with Data and call the JavaScript function CreateGridHeader() from server side. This JavaScript function is also called on page load. string conString = "Provider=Microsoft.JET.OLEDB.4.0; 5. The CreateGridHeader () function needs to be called on Page Load also. protected void Page_Load(object sender, EventArgs e)You are now ready with the GridView with fixed headers. [color#FF4000]Points of Interest[/color] This solution is tested well with Internet Explorer, Mozilla Firefox, and Google Chrome This attachment is hidden for guests. Please log in or register to see it.
Attachments:
|
|
|
|
|
Time to create page: 0.69 seconds







