Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a spgridview with dynamic column.

I want fix width and if the content is a part of it is displayed.

I use this code but don't work for me .

BoundField col = new BoundField();
col.HeaderText = field.Title;
col.HeaderStyle.Width = new Unit(50);
col.DataField = field.InternalName;

for fix height i use this code.

  e.Row.Height = new Unit(25);
            if (grid.Columns.Count > 1)
                for (int i = 1; i < grid.Columns.Count; i++)
                {
                    e.Row.Cells[i].Wrap = false;
                }
share|improve this question
How does the css look like? Is it somewhere there that makes the text unwrap or set the table cells sizes? Otherways you can control it there which I belive is the best thing and not by units from ASP.NET (which will be inline css). – Magnus Hansson Mar 7 at 7:02

3 Answers

Create an handler for the RowDataBound event of the grid and inside that handler set the width for the cells. You can use something similar to the following:

e.Row.Cells[x].Style.Add(HtmlTextWriterStyle.Width, "100px");
share|improve this answer

Have you tried? grid.Columns[i].ItemStyle.Width = 200

share|improve this answer
Thanks, i use this code but don't work. it is fix with content :( – ar.gorgin May 31 '12 at 7:47

It should be col.HeaderStyle.Width = Unit.Pixel(50);

share|improve this answer
Thanks, i use this code but don't work. it is fix with content :( – ar.gorgin May 31 '12 at 7:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.