Category : .Net | Author : Chtiwi Malek | First posted : 3/27/2012 | Updated : 4/27/2012
Tags : asp.net, css, gridview, visual studio
Styling the GridView Cell Item

Styling the GridView Cell Item

Today, I’ve got a question from an Asp.net developer :

How can I format all cells in a GridView ? I want to add a 5px padding to all cells including headers, I’ve added CellPadding="5" to my Gridview but it doesn’t work.

To do that, just add this line to each item in the GridView Columns:

<ItemStyle CssClass="MyCssClass" />

Example :
<Columns>

 <asp:BoundField DataField="name" HeaderText="Product Name">
  <ItemStyle CssClass="MyCssClass" />
 </asp:BoundField>

 <asp:BoundField DataField="qty" HeaderText="Qty">
  <ItemStyle CssClass="MyCssClass" />
 </asp:BoundField>

 <asp:BoundField DataField="price" HeaderText="Price">
  <ItemStyle CssClass="MyCssClass" />
 </asp:BoundField>

</Columns>
The same thing can be achieved from Design View:

Open the Gridview Tasks menu (Top-Right of the Gridview), select Edit Columns and choose a Field and scroll down to the Header Style and Item Style, and add your Css class name.
Comments & Opinions :
sdvsd
sdvdsvsafvsdv
- by adxad on 12/31/2019
sdvsd
sdvdsvsafvsdv
- by adxad on 12/31/2019
Leave a Comment:
Name :
Email : * will not be shown
Title :
Comment :