GridView Truncate Heading

we have a gridview that we are manually setting up the columns in.

the column widths are defined by the user, but occasionly they specify a width that is smaller than required for the heading text.

the gridview automatically resizes the column and makes the other columns slightly smaller to fix this up.

the problem is that we dynamically add controls above and below the gridview to filtering and totalling so when the gridview is automatically resized the controls dont match up.

when we ask the column width, even after calling the databind method, it returns the width we set it as, no what it has been resized too.

how do i get the real column width, or if that isn't possible, could i somehow truncate the heading so it stays the correct width.

note: when i talk about columns, i'm referrring to DataControlField's which are what dataview's call columns.
LVL 3
mpdaltonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nauman_ahmedCommented:
You need to handle that at Row_Created event. A code snippet is given below but you will need to modify it according to your requirement:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        int INT_WIDTH_LIMIT = 18;
        if (e.Row.RowType == DataControlRowType.Header)
        {
           if (e.Row.Cells[CELL_INDEX].Text > INT_WIDTH_LIMIT)
           {
              e.Row.Cells[CELL_INDEX].Text  = e.Row.Cells[2].Text.Substring(0,15)+"...";
           }
          //Calculate the width for other Header
        }
    }

-Nauman.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mpdaltonAuthor Commented:
thanks for your answer, i've realised after a bit of work that truncating isn't going to work for me as i allow the field to wrap if it has multiple words.

i'll give you the points since your answer was right and reask the question.

cheers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.