Joseph
Joseph

Reputation: 661

Cannot set row height on a gridview control

Here is my ASP:

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateEditButton="true" 
    DataSourceID="AccessDataSource1"
    AutoGenerateColumns="False" DataKeyNames="ID"
    RowStyle-CssClass="editPhotoGridFormat" 
    AlternatingRowStyle-CssClass="editPhotoGridFormat"
    AlternatingRowStyle-BackColor="Gray" 
    RowStyle-Height="400px" 
    RowStyle-VerticalAlign="Top">
    <RowStyle Height="400px" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
            ReadOnly="True" SortExpression="ID" />
        <asp:BoundField DataField="BlogTitle" HeaderText="BlogTitle" 
            SortExpression="BlogTitle" />
        <asp:ImageField DataImageUrlField="Image" HeaderText="Image"
            DataImageUrlFormatString="~/PlaceImages/{0}" ControlStyle-CssClass="editPhotoGridFormat"
            AlternateText="Something went wrong" 
            NullDisplayText="No picture on file" />
        <asp:BoundField DataField="PicText" HeaderText="PicText" />
        <asp:BoundField DataField="TravelDate" HeaderText="TravelDate" SortExpression="TravelDate" />
        <asp:BoundField DataField="BeginText" HeaderText="BeginText" ItemStyle-Height="10px" />
        <asp:BoundField DataField="Caption" HeaderText="Caption" />
        <asp:BoundField DataField="City" HeaderText="City" />
        <asp:BoundField DataField="Country" HeaderText="Country" 
            SortExpression="Country" />
        <asp:BoundField DataField="EndText" HeaderText="EndText" />
    </Columns>

</asp:GridView>

Here's my CSS:

.editPhotoGridFormat
    {
        width: 220px;
        height: 180px;
    }

It seems like no matter where I set height, it doesn't want to change the height of my rows. You can see that I have set the height in many places in my code, and I've tried using each one individually. Any ideas folks? All the posts on gridview row height here seem to be for Android, lol.

Upvotes: 1

Views: 8549

Answers (2)

amitesh
amitesh

Reputation: 860

Try this

<asp:GridView ID="GridView1"> <rowstyle Height="20px" /></asp:GridView>

OR

Mention the height value for RowStyle(& AlternateRowStyle) in your HTML source

You can do that same in code-behind

GridView1.RowStyle.Height = 50;

But my suggestion is use CSS(Best way)

.RowStyle {
 height: 50px;
 }
.AlternateRowStyle {
 height: 50px;
 }

HTML Source

 <asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
  RowStyle-CssClass="RowStyle"
  AlternatingRowStyle-CssClass="AlternateRowStyle">
 </asp:gridview>

Upvotes: 1

Arun Bertil
Arun Bertil

Reputation: 4648

Have you tried to set the row height in your css?

Set this style in the CssClass properties for the RowStyle and AlternateRowStyle styles of your GridView:

.smallRow 
{
  height: 150px;
}

Upvotes: 0

Related Questions