Datagrid Header problem

Posted on 2005-04-19
Medium Priority
Last Modified: 2010-04-07
Hi there,

I am using a datagrid to show results that are pulled back from a sql server database. All the datagrid columns are bound columns and the datagrid could have up to 1000 records. I have done all of this and am at the point we they are wanting fixed headers for the datagrid. So i used a html table to provide the headers and made the datagrid headers "invisble". The thing is that i have made the datagrid columns fixed widths but they still grow in size beacuse of the size of some of the results that are pulled back from the DB.

Does anyone know how to stop this from happeneing or a way to get the widths of the datagrid columns and make the html table widths that same size??

Question by:NiallGray
  • 3
  • 2
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 13815412
Why is it that you have an html table for displaying headers?

I dont see why this is necassary as you can name a column header anything you like.

Author Comment

ID: 13815433
So to have static headers when scrolling through all the records in the datagrid.
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 13815502
Oh I see....

You mean the header will be displayed even whilst scrolling the grid right?

You can count the characters in each field and try to resize your html header columns that way. You can loop thru your dataset and count field lengths. Then you can use some sort of formula to determine what the width of your html columns should be.
Independent Software Vendors: 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!

LVL 26

Expert Comment

ID: 13815789
>>i used a html table to provide the headers and made the datagrid headers "invisble". The thing is that i have made the datagrid columns fixed widths
How did u do this? Note that the column widths are assigned to the headerStyle tags and not to individual columns. So if u do not have headers then probably ur HTML generated for the grid will not have the width specified .. check it by "viewing the source" of the HTML page generated

try doing it this way
<HeaderStyle Width="10%"></HeaderStyle>
This might give u the header .. just check if the data still overflows? If it does not, then u can be sure the problem is with the column not taking effect without the headers

try adding this style to ur grid style class - "CssClass"
table-layout: fixed;
LVL 26

Accepted Solution

Rejojohny earned 600 total points
ID: 13815854
ok .. i found this example which is exactly what u wanted .. it uses the ItemStyle-Width of the bound column to assign the width ..
Creating a Scrollable DataGrid with a Fixed Header

The demo is here
LVL 26

Expert Comment

ID: 13864329
thx for the pnts .. but any particular reason for a grade B .. anyway there is feature in ASP.net with SP1 .. a property exposed for the datagrid, using which and a style sheet the same can be acheived .. i had read an artcile somwhere (i think code project site).. but cannot find it now ..

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question