First of all you should add autogeneratecolumns="false" to your <asp:GridView>
Your aspx files should look like this:
<asp:GridView ID="GridView1" CssClass="gridview" autogeneratecolumns="False" Width="900" runat="server" HeaderStyle-CssClass="HeaderStyle">
<Columns>
<asp:boundfield DataField="field0">
<HeaderStyle CssClass="HeaderStyle" />
<ItemStyle CssClass="ItemStyle" />
<FooterStyle CssClass="HeaderStyle" />
<ControlStyle CssClass="HeaderStyle" />
</asp:boundfield>
<asp:boundfield DataField="field1">
<HeaderStyle CssClass="HeaderStyle" />
<ItemStyle CssClass="ItemStyle" />
<FooterStyle CssClass="HeaderStyle" />
<ControlStyle CssClass="HeaderStyle" />
</asp:boundfield>
.........
</Columns>
</asp:GridView>
Your CSS file may be like this:
.HeaderStyle
{
background-color: #900;
color: White;
font-weight: bold;
white-space:nowrap;
width: 100px;
max-width: 100px;
overflow: hidden;
}
.ItemStyle
{
background-color: #eaebec;
color: Black;
font-weight: bold;
white-space:nowrap;
width: 100px;
max-width: 100px;
overflow: hidden;
}
.gridview {
font-family: Arial, Helvetica, sans-serif;
color: #666;
font-size: 12px;
background: #eaebec;
margin: 20px;
border: #ccc 1px solid;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-moz-box-shadow: 0 1px 2px #d1d1d1;
-webkit-box-shadow: 0 1px 2px #d1d1d1;
}
You asked this question for c# but I will add VB codes here, however you can convert it:
Dim tablo As New DataTable
Dim row As DataRow
tablo.Columns.Add("field0", System.Type.GetType("System.String"))
tablo.Columns.Add("field1", System.Type.GetType("System.String"))
.......
For i = 1 to XX
row("field" + Trim(Str(i))) = "Something"
Next
tablo.Rows.Add(row)
GridView1.Columns(0).HeaderText = "Something Header"
GridView1.Columns(1).HeaderText = "Something Other Header"
.......
I think that's all. Hope it helps.
RowStyle-Wrapof the GridView toTrue. With<RowStyle Width="15%" />- Mahesh