Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

Grid view horizontal spacing

I have created an asp.net gridview. I don't want cellspacing and my cellpadding=1. I want to keep the vertical space narrow, but I need more space between columns horizontally. They are too close together.

Is there a way to do that?

thanks!
Avatar of samtran0331
samtran0331
Flag of United States of America image

basically, you want to set the row height right?
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
            DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." AlternatingRowStyle-Height="50px" RowStyle-Height="50px">
....

Open in new window

Avatar of Starr Duskk

ASKER

See title. LOL. Sorry, but no, I want gridview horizontal spacing....

>> I need more space between columns horizontally. They are too close together.
I ended up creating a padding class:

.gridPadder
{
    padding: 0, 5px, 0, 5px;
}
and adding it to each TemplateField that needs padding:

<HeaderStyle CssClass="gridPadder" />

I tried adding it to the gridview Headerstyle, but that didn't work.

My headers are wider than my text, so it works just there. If my item were wider, I'd have to add it there:

<ItemStyle HorizontalAlign="Center" CssClass="gridPadder" />
I get my horizontal/vertical mixed up sometimes...let me test the CssClass route, but you can still force the width:

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
            DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." AlternatingRowStyle-Height="50px" RowStyle-Height="50px">
            <Columns>
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" ItemStyle-Width="300px" />
....
Well, that's nice to know. But I do want it padded based on the width of the text but a bit wider so the columns don't butt together.

Maybe we crossed paths, but I did find a solution.

If you have a more graceful one that calls for padding in the control to apply throughout that would be great. But looks like there is no such thing.

thanks.
sam tran,

btw, did you see  my comment on:
https://www.experts-exchange.com/questions/22985466/asp-net-2-0-setting-field-focus.html

I don't know how to "reach" you otherwise I'd sent this private.

thanks.
btw, we have a nascar race track down the road from us too. vroom. argh.
ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial