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