11
  • I autoformat a GridView in ASP.NET.
  • It looks nice but the headers all run together like this:

    idfirstNamelastNameage

  • I set CellPadding="5" but it does nothing.

How can I set the cell padding of the headers and all cells?

A D D E N D U M :

Thanks Andrew, I fixed it with this. Works in Firefox and Explorer 7:

.gridview2 tr td
{
    padding: 5px;
    border: 1px solid #ddd;
}
.gridview2 tr th
{
    padding: 5px;
}

3 Answers 3

11

You should set a cssclass and use css to control it. The only property of a table you cant fully control cross browser with css is cellspacing.

.myTableClass tr th {
    padding: 5px;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Update: Bear in mind this is 5 years old, only ancient versions of IE suffer from the cellspacing css issue
4

GridView also has a property "CellPadding" and "CellSpacing" that can help us do this.

Comments

0

Check the generated HTML and find the table it has created. Check the ID of the table. With the id, add following lines to your CSS. This worked for me when all else failed..

#YourTableIdFoo th , #YourTableIdFoo td 
{
    padding-right:      1em;
}

1 Comment

The generated html table has no id attribute, even when the GridView in the markup has one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.