我有一个 asp.net 网格视图。这些行和列是根据从数据库中检索到的值动态生成的。在 .aspx 页面中,我使用网格
<asp:GridView Height="250" Width="100%" runat="server" />
如果我有更多的行数,那么网格如下所示。
如果我只有一排网格,则如下所示。
但是即使只有单行,我也想显示与第一张图像相同的网格行高度。如何将网格行高值设置为固定值。我在stackoverflow中发现了一些类似的问题。但那些并没有给我解决方案。
我有一个 asp.net 网格视图。这些行和列是根据从数据库中检索到的值动态生成的。在 .aspx 页面中,我使用网格
<asp:GridView Height="250" Width="100%" runat="server" />
如果我有更多的行数,那么网格如下所示。
如果我只有一排网格,则如下所示。
但是即使只有单行,我也想显示与第一张图像相同的网格行高度。如何将网格行高值设置为固定值。我在stackoverflow中发现了一些类似的问题。但那些并没有给我解决方案。
您可以GridView.RowStyle Property
用于定义行样式
GridView.RowStyle 属性:获取对 TableItemStyle 对象的引用,该对象使您能够设置 GridView 控件中数据行的外观。
例如。
<asp:GridView ID="GridView1">
<rowstyle Height="20px" />
<alternatingrowstyle Height="20px"/>
</asp:GridView>
CSS:/网格/
.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; }
来源 :
<asp:GridView ID="GridView2" runat="server" CssClass="MoGrid"
PagerStyle-CssClass="pgrM" AlternatingRowStyle-CssClass="alt">
有点棘手,但为我工作。您可以通过说明 gridview 本身的高度(以 px 为单位)来使 gridview 固定高度。现在要使行收缩到适当的高度(而不是扩大以填充空白),将页脚样式的高度设置为 100%。这样可以确保即使显示的记录数小于分页大小,页脚也会占用空间,使数据行保持其原始“未扩展”状态。
第一的:
showfooter="true"
在网格中。
在页脚样式中:
<footerstyle Height="100%" />
您可以在此代码 onPage_PreRender 中使用 gridview 的 RowStyle-Height="20" 属性
例如
if(grdView.Rows.Count>0)
grdView.Height = new Unit(grdView.RowStyle.Height.Value * grdView.Rows.Count);
或者remove Height property from gridView
有很多方法
在 HTML 源代码中提及 RowStyle(& AlternateRowStyle) 的高度值
<rowstyle height="50" />
您可以在代码隐藏中执行相同的操作
GridView1.RowStyle.Height = 50;
但我的建议是使用 CSS(最佳方式)
.RowStyle {
height: 50px;
}
.AlternateRowStyle {
height: 50px;
}
ASP 源码
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
<rowstyle cssclass="RowStyle" />
<alternatingrowstyle cssclass="AlternateRowStyle" />
</asp:gridview>
谢谢