?
Solved

GridView Truncate Heading

Posted on 2006-03-21
2
Medium Priority
?
1,229 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:mpdalton
2 Comments
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 2000 total points
ID: 16253014
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
 
LVL 3

Author Comment

by:mpdalton
ID: 16253430
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Integration Management Part 2
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…
Suggested Courses

807 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