如何降低asp.net gridview控件的整体高度?

时间:2012-07-16 16:56:24

标签: asp.net gridview

我试图降低此gridview的整体高度,因此没有那么多"空行"在底部。我尝试设置高度属性。我还尝试将PagingSize设置为较小的数字并设置AllowPaging Attribute = true

数据源将返回可变数量的行,但gridview需要固定高度。现在,它占据的垂直房地产数量远远超过任何最大数量的HearingInfo甚至可以达到。换句话说,底部有足够的空间至少10行,但永远不会有10行。

我暂时没有使用ASP.net网页控件......

        <asp:GridView ID="gvHearingInfo" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" 
            ShowHeader="False" Width="100%" GridLines="Vertical" 
            Height="50px">
            <Columns>
                <asp:BoundField DataField="Authority" HeaderText="Authority" 
                    SortExpression="Authority">
                <ItemStyle Width="144px" Wrap="False" HorizontalAlign="Left" 
                    BorderColor="Black" />
                </asp:BoundField>
                <asp:BoundField DataField="PublicHearing" HeaderText="PublicHearing" 
                    SortExpression="PublicHearing" >
                <ItemStyle HorizontalAlign="Left" Width="431px" BorderColor="Black"  />
                </asp:BoundField>
                <asp:BoundField DataField="HearingDate" HeaderText="HearingDate" 
                    SortExpression="HearingDate" >
                <ItemStyle HorizontalAlign="Center" Width="93px" BorderColor="Black"  />
                </asp:BoundField>
                <asp:BoundField DataField="HearingTime" HeaderText="HearingTime" 
                    SortExpression="HearingTime" >
                <ItemStyle HorizontalAlign="Center" Width="92px" BorderColor="Black"  />
                </asp:BoundField>
                <asp:BoundField DataField="DistrictTelephone" HeaderText="DistrictTelephone" 
                    SortExpression="DistrictTelephone" >
                <ItemStyle HorizontalAlign="Center"  Width="94px" BorderColor="Black"  />
                </asp:BoundField>
            </Columns>
        </asp:GridView>

1 个答案:

答案 0 :(得分:0)

Results.DataSource = dataView;

Results.DataBind();

foreach(GridViewRow row in this.Results.Rows) 
{
   if (row.Equals(""))
     {
      Results.Rows[0].Visible = false;
     }

}

或者你必须使用GridView.RowDataBound事件,但我认为代码应该完成工作...