是否可以在gridview的单元格中滚动?

时间:2011-03-09 08:05:08

标签: c# asp.net gridview

我的gridview中有一些记录。但是每个记录都存在问题,有一个单元格包含大量数据。我仍然想显示数据并允许用户向下滚动阅读(如果他们感兴趣)。是否有可能允许在该单元格中滚动?

编辑:

这是我提到的css:

    .AspNet-GridView
    {
        overflow: auto;
        height:400px;
    }
    .AspNet-GridView table thead tr th
    {
        height:20px;
        position:relative;
    }
    .AspNet-GridView table tbody
    {
        overflow: auto;
    }

编辑2: 这是gridview,我希望带有headertext主体的列允许滚动。

<asp:GridView ID="gvAanvragen" 
    OnPageIndexChanging="GvAanvragen_PageIndexChanging" runat="server" AllowPaging="True" 
    AllowSorting="True" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" 
    BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" 
    PageSize="5" AutoGenerateColumns="false" AutoGenerateSelectButton="True" 
        onselectedindexchanged="GvAanvragen_SelectedIndexChanged" 
        CssClass="AspNet-GridView">
    <RowStyle BackColor="#F7F7DE" />
    <FooterStyle BackColor="#CCCC99" />
    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:BoundField HeaderText="ID" DataField="ID" />
        <asp:BoundField HeaderText="Subject" DataField="Subject" />
        <asp:BoundField HeaderText="Body" DataField="Body" HtmlEncode="false" />
        <asp:BoundField HeaderText="Sent" DataField="Sent" />
    </Columns>
</asp:GridView>

有人能帮助我吗?

3 个答案:

答案 0 :(得分:6)

您可以使用模板列并在其中放置一个带有style="overflow:auto;"

的div
<asp:TemplateField>
    <ItemTemplate>
         <div style="overflow:auto; height: 100px;"><Your Content here></div> 
    </ItemTemplate>
</asp:TemplateField>

答案 1 :(得分:4)

要添加Naveed的答案,现在您已经发布了原始代码:http://www.asp.net/data-access/tutorials/using-templatefields-in-the-gridview-control-cs有一个很好的数据绑定模板字段示例:

<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

在您的情况下,只需替换

<asp:BoundField HeaderText="Body" DataField="Body" HtmlEncode="false" />

通过Naveed提供的代码,并在此示例中添加数据绑定,并最终得到如下内容:

<asp:TemplateField HeaderText="Body">
    <ItemTemplate>
        <div style="overflow:auto; height: 100px;">
            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Body")%>'></asp:Label>
        </div>
    </ItemTemplate>
</asp:TemplateField>

如果您不想使用标签,请改用文字控件:

<asp:Literal ID="Literal1" runat="server" Text='<%# Bind("Body")%>' />

答案 2 :(得分:1)

您可以添加模板列,并在该列内部将所有内容放入带有溢出设置的div中(请参阅CSS溢出)。

相关问题