0

チェックボックスリストを含むasp.netパネルがあります。幅がリストの内容にぴったり合うようにサイズを変更したいと思います。

現在、パネルの事前レンダリング イベントを処理しており、その幅をチェックボックス リストの幅と一致するように設定しています。ただし、checkboxlist の width プロパティが (少なくともこの pre render メソッドでは) ゼロを読み取っているように見えるため、パネルの幅が同じように設定されているため、Firefox と IE で一貫性のないレンダリングが発生します。私がここで試みていることを行うためのより良いアプローチを持っている人はいますか? どうもありがとう。

4

1 に答える 1

0

javascript ごとに onload のパネル幅を設定できます。

<script>
function resizePanel() {
            var panel = document.getElementById('Panel1');
            var checkBox = document.getElementById('CheckBoxList1')
            if (panel != null && checkBox != null)
                panel.style.width = checkBox.offsetWidth + "px";
}
</script>
</head>
<body onload="resizePanel()">
    <form id="form1" runat="server">
    <asp:Panel ID="Panel1" runat="server" BorderWidth="1" BorderColor="Silver">
    <asp:CheckBoxList ID="CheckBoxList1" Width="200px" runat="server">
    <asp:ListItem Text="Item 1" Value="1"></asp:ListItem>
    <asp:ListItem Text="Item 2" Value="2"></asp:ListItem>
    <asp:ListItem Text="Item 3" Value="3"></asp:ListItem>
    <asp:ListItem Text="Item 4" Value="4"></asp:ListItem>
    <asp:ListItem Text="Item 5" Value="5"></asp:ListItem>
    <asp:ListItem Text="Item 6" Value="6"></asp:ListItem>
    <asp:ListItem Text="Item 7" Value="7"></asp:ListItem>
    </asp:CheckBoxList>
    </asp:Panel>
    </form>
</body>
</html>
于 2010-05-05T21:33:13.377 に答える