我的树视图无视我创建更紧凑视图的愿望。树视图延伸到我的页面高度以下,所以我试图让它坐在一个大约300px的面板或div内。无论我在哪里放置div或面板标签,它似乎都不会改变高度,树视图会一直持续到数据结束。有人可以帮忙吗?
这是我的代码:
<script type="text/javascript">
// It is important to place this JavaScript code after ScriptManager1
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
function BeginRequestHandler(sender, args) {
if ($get('<%=Panel1.ClientID%>') != null) {
// Get X and Y positions of scrollbar before the partial postback
xPos = $get('<%=Panel1.ClientID%>').scrollLeft;
yPos = $get('<%=Panel1.ClientID%>').scrollTop;
}
}
function EndRequestHandler(sender, args) {
if ($get('<%=Panel1.ClientID%>') != null) {
// Set X and Y positions back to the scrollbar
// after partial postback
$get('<%=Panel1.ClientID%>').scrollLeft = xPos;
$get('<%=Panel1.ClientID%>').scrollTop = yPos;
}
}
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
</script>
<asp:Panel ID="FPanel" runat="server" Height="300px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Height="300px">
<div style="height:300px">
<asp:TreeView ID="TreeViewAccts" runat="server" ShowLines="true" PopulateNodesFromClient="false" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged1" Height="118px" ShowExpandCollapse="true" Font-Size="X-Small" Width="645px" NodeIndent="10" Font-Bold="True" ForeColor="DarkBlue" ExpandDepth="0">
<NodeStyle VerticalPadding="1"
Font-Names="Courier"
Font-Size="8pt"
NodeSpacing="0"
HorizontalPadding="5"
BorderStyle="Solid"
BorderColor="DarkCyan"
BorderWidth="1"
BackColor="White"
Width="640">
</NodeStyle>
</asp:TreeView>
<asp:TextBox ID="txtTreeselect" runat="server" Enabled="False" Visible="False"></asp:TextBox>
<asp:HiddenField ID="xCoordHolder" runat="server" />
<asp:HiddenField ID="yCoordHolder" runat="server" />
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
答案 0 :(得分:0)
知道了。对于任何感兴趣的人,面板的属性都会执行此操作,称为“ScrollBars”。
我改变了
<asp:Panel ID="FPanel" runat="server" Height="300px">
到
<asp:Panel ID="FPanel" runat="server" Height="300px" ScrollBars="Vertical">
添加后,我能够完全删除div标签,一切都按预期工作。