【问题标题】:ASP Grid View, predifine the row height sizeASP Grid View,预定义行高大小
【发布时间】:2012-10-14 05:11:33
【问题描述】:

我有一个带有两个动态列的 Asp Gridview。一列将显示一组字符(描述),另一列用于显示图像。 我只是想限制这个描述网格行高。

<div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EnableModelValidation="True"
                  AllowPaging="True" GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="Label_dynamicDes" runat="server" Text='<%#Bind("description") %>'></asp:Label> <br/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:ImageField DataImageUrlField="picpath" ControlStyle-Width='200px'>
                <ControlStyle Width="200px"></ControlStyle>
            </asp:ImageField>
        </Columns>
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource_dynamic" runat="server">
    </asp:SqlDataSource>

</div>

如何控制 GridView 行大小的高度?我不能在后面的代码中做到这一点。请帮我用一些css函数来预定义动态行的大小?

【问题讨论】:

    标签: c# asp.net css gridview dynamic-data


    【解决方案1】:

    您可以从代码后面或标记中设置RowStyleAlternatingRowStyle。详情请见MSDN

    编辑:

    您可以像这样在标记中设置RowStyle-CssClass

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource1" EnableModelValidation="True"
    AllowPaging="True" GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged"
    RowStyle-CssClass="my-table-row-style">
    

    在后面的代码中这样设置:

    GridView1.RowStyle.CssClass = "my-table-row-style";
    

    或者像这样纯粹用 CSS 来做:

    #GridView1 td
    {
        height: 90px;
    }
    

    【讨论】:

      【解决方案2】:

      我假设您不希望行的高度大于图像的高度(假设为 90 像素)。您可以在 TemplateField 中放置一个固定高度的 div 并设置高度

         <asp:TemplateField>
          <ItemTemplate>
      
             <div style="height:90px; overflow:auto">
              <asp:Label ID="Label_dynamicDes" runat="server" Text='<%#Bind("description") %>'></asp:Label>
             </div>
      
          </ItemTemplate>
         </asp:TemplateField>
      

      当描述超过高度时,由于overflow:auto,div会有滚动条。你也可以有overflow:scroll

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-04
        • 2014-10-12
        • 2019-02-17
        • 1970-01-01
        • 1970-01-01
        • 2018-09-16
        • 1970-01-01
        相关资源
        最近更新 更多