固定了 asp.net 滚动时列表视图中的标题

本文关键字:视图 列表 标题 滚动 asp net | 更新日期: 2023-09-27 18:32:37

当我向列表视图添加新行时,最高高度为200px,之后它将滚动,而滚动标题也在滚动.如何修复此标题应该是恒定的

<asp:ListView ID="listview1" runat="server">
        <LayoutTemplate>
            <table runat="server" cellpadding="1" border="1"  style="background-color: #FFFFFF;
                border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                <tr style="background-color: #E5E5FE">
                    <th>
                        Order
                    </th>
                    <th>
                        Column Title
                    </th>
                    <th>
                        DataType
                    </th>
                    <th>
                        Exapmles
                    </th>
                    <th>
                        Options
                    </th>
                    <th>
                       Delete
                    </th>
                </tr>
                <tr id="itemplaceholder" runat="server">
                </tr>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label ID="txtorder" Text='<%#Eval("OrderNo") %>' runat="server"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtcolumnname" Text='<%#Eval("ColumnTitle") %>' runat="server" Width="150"></asp:TextBox>
                </td>
                <td>
                <asp:DropDownList ID="ddldatatype" runat="server" Width="160"   >
                </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="ddlexamples"  runat="server" Width="160">
                      <asp:ListItem Text="test" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                <asp:TextBox ID="txtoptions" Text='<%#Eval("Options") %>' runat="server" Width="150" ></asp:TextBox>
                </td>
                <td>
               <asp:CheckBox ID="chkdel" runat="server" />
                </td>
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <tr style="background-color: #EFEFEF">
                <td>
                    <asp:Label ID="txtorder" Text='<%#Eval("OrderNo") %>' runat="server"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtcolumnname" Text='<%#Eval("ColumnTitle") %>' runat="server" Width="150"></asp:TextBox>
                </td>
                <td>
                <asp:DropDownList ID="ddldatatype" runat="server" Width="160" >
                </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="ddlexamples" runat="server" Width="160">
                      <asp:ListItem Text="test" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                <asp:TextBox ID="txtoptions"  Text='<%#Eval("Options") %>' runat="server" Width="150"></asp:TextBox>
                </td>
                <td>
               <asp:CheckBox ID="chkdel" runat="server" />
                </td>
            </tr>
        </AlternatingItemTemplate>
    </asp:ListView>
  </div>
    <br />
    <br />
    <asp:Button ID="btnAdd" runat="server" Text="Add New Row" OnClick="btnAdd_Click" />
      &nbsp &nbsp
            <asp:Button ID="btndelete" runat="server" Text="Delete" onclick="btndelete_Click" />           
            </td>         
        </tr>
    </table>

固定了 asp.net 滚动时列表视图中的标题

您可以尝试将标题与内容分开,并将标题放在可滚动内容之外。

<div>Some Page Content </div>
    //your heading goes here
    <div style="max-height: 200px; overflow: auto;">
       //your listview goes here
    </div>
<div>Some Page Content </div>

喜欢这个

   <div style="float:left; width:100%;" >
        <table id="Table1" runat="server" cellpadding="1" border="1" style="background-color: #FFFFFF;
            border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px;width:100%;">
            <tr style="background-color: #E5E5FE">
                <th style="width:15%;">
                    Order
                </th>
                <th style="width:15%;">
                    Column Title
                </th>
                <th style="width:15%;">
                    DataType
                </th>
                <th style="width:15%;">
                    Exapmles
                </th>
                <th style="width:15%;">
                    Options
                </th>
                <th style="width:25%;">
                    Delete
                </th>
            </tr>
        </table>
    </div>
   <div style="max-height: 200px; overflow: auto; float:left; width:100%;">
        <asp:ListView ID="listview1" runat="server">
            <LayoutTemplate>
                <table id="Table1" runat="server" cellpadding="1" border="1" style="background-color: #FFFFFF;
                    border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px;
                    ">
                    <tr style="background-color: #E5E5FE;display:none;">
                        <th>
                            Order
                        </th>
                        <th>
                            Column Title
                        </th>
                        <th>
                            DataType
                        </th>
                        <th>
                            Exapmles
                        </th>
                        <th>
                            Options
                        </th>
                        <th>
                            Delete
                        </th>
                    </tr>
                  <tr id="itemplaceholder" runat="server">
                    </tr>
                </table>

            </div>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td style="width:15%;">
                         <asp:Label ID="txtorder" Text='<%#Eval("OrderNo") %>' runat="server"></asp:Label>
                    </td>
                    <td style="width:15%;">
                        <asp:TextBox ID="txtcolumnname" Text='<%#Eval("ColumnTitle") %>' runat="server" Width="150"></asp:TextBox>
                    </td>
                    <td style="width:15%;">
                        <asp:DropDownList ID="ddldatatype" runat="server" Width="160">
                        </asp:DropDownList>
                    </td>
                    <td style="width:15%;">
                        <asp:DropDownList ID="ddlexamples" runat="server" Width="160">
                            <asp:ListItem Text="test" Value="2"></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td style="width:15%;">
                        <asp:TextBox ID="txtoptions" Text='<%#Eval("Options") %>' runat="server" Width="150"></asp:TextBox>
                    </td>
                    <td style="width:25%;">
                        <asp:CheckBox ID="chkdel" runat="server" />
                    </td>
                </tr>
            </ItemTemplate>
            <AlternatingItemTemplate>
                <tr style="background-color: #EFEFEF">
                    <td>
                      <asp:Label ID="txtorder" Text='<%#Eval("OrderNo") %>' runat="server"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtcolumnname" Text='<%#Eval("ColumnTitle") %>' runat="server" Width="150"></asp:TextBox>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddldatatype" runat="server" Width="160">
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlexamples" runat="server" Width="160">
                            <asp:ListItem Text="test" Value="2"></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:TextBox ID="txtoptions" Text='<%#Eval("Options") %>' runat="server" Width="150"></asp:TextBox>
                    </td>
                    <td>
                        <asp:CheckBox ID="chkdel" runat="server" />
                    </td>
                </tr>
            </AlternatingItemTemplate>
        </asp:ListView>
    </div>