How to set fixed width and height for grid row which is dynamically generating in asp.net

You can use GridView.RowStyle Property for defining the row style

GridView.RowStyle Property: Gets a reference to the TableItemStyle object that enables you to set the appearance of the data rows in a GridView control.

Eg.

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

CSS : /grid/

.MoGrid { width: 100%; background-color: #fff; margin: 5px 0 10px 0;}

.MoGrid td { color: #F05117;font-family: georgia;font-weight: bold;padding: 30px 2px 2px;}

.MoGrid th {border-bottom: 1px solid #F05117;border-top: 1px solid #F05117;color: #29B6EA;
    font-size: 13px;font-weight: bold;padding: 4px 2px;font-family: georgia;}

.MoGrid .alt { background: #fcfcfc url(../Styles/images/grd_alt.png) repeat-x top; }

.MoGrid .pgrM {background: #29B6EA; height:10px; }

.MoGrid .pgrM table { margin: 5px 0; }

.MoGrid .pgrM td { border-width: 0; padding: 0 6px; border-left: solid 1px #666; font-weight: bold; color: #fff; line-height: 12px; float:left; }  

.MoGrid .pgrM a { color: #666; text-decoration: none; }

.MoGrid .pgrM a:hover { font-family: tahoma;font-size: 12px;background-color: #99BBE1; }

SOURCE :

<asp:GridView ID="GridView2" runat="server" CssClass="MoGrid"       
PagerStyle-CssClass="pgrM" AlternatingRowStyle-CssClass="alt">

Little bit tricky but work for me. You can make the gridview fixed height by stating the height (in px) of the gridview itself. Now to make the rows contract down to their appropriate height (rather than expanding to fill the void) set the Height of the Footer Style to 100%. This ensures that even if the number of records displayed is less than the paging size the footer will take up the slack, leaving the data rows in their original "unexpanded" state.

First:

showfooter="true" 

in grid.

and in footerstyle :

  <footerstyle Height="100%" />

Tags:

Asp.Net