Datagrid Header problem

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??

Who is Participating?
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
Ramesh SrinivasTechnical ConsultantCommented:
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.
NiallGrayAuthor Commented:
So to have static headers when scrolling through all the records in the datagrid.
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Ramesh SrinivasTechnical ConsultantCommented:
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.
>>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;
thx for the pnts .. but any particular reason for a grade B .. anyway there is feature in 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 ..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.