Datagrid Header problem

Posted on 2005-04-19
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
    LVL 11

    Expert Comment

    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

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

    Expert Comment

    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.
    LVL 26

    Expert Comment

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

    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

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

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now