Is it possible to scroll in a cell of a gridview?

假装没事ソ 提交于 2019-12-12 21:18:16

问题


I have some records in my gridview. But there is a problem in each record, there is one cell which contains a HUGE amount of data. I still want to display data and allow the users to scroll down to read (if they're interested). Is there a possibility to allow scrolling in that cell?

EDIT:

This is the css I refer to:

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

EDIT 2: this is the gridview and I want The column with the headertext body to allow scrolling.

<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>

Can someone help me please?


回答1:


To add to Naveed's answer, now that you've posted your original code: http://www.asp.net/data-access/tutorials/using-templatefields-in-the-gridview-control-cs has a good example of a data bound template field:

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

In your case, just replace the line

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

by the code Naveed provided, and add the databinding as in this example, and you endup with something like:

<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>

If you don't want to use a label, then use a literal control instead:

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



回答2:


You can use Template Column and place a div inside it with style="overflow:auto;"

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



回答3:


You could add a template column and inside of that column put all your content inside a div with overflow set (refer to CSS overflow).



来源:https://stackoverflow.com/questions/5242916/is-it-possible-to-scroll-in-a-cell-of-a-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!