CheckBox列表来自动态值

时间:2015-08-17 15:17:53

标签: html vbscript asp-classic

我正在使用VB中的一个经典ASP页面,我对此并不十分熟悉。我正在尝试改变这个

enter image description here

到这个

enter image description here

这应该是非常直接的,除非看起来列表是动态的并且它绊倒我。

 <% sendtomenu = sendtomenu + "<option value = " & trim(Recordset2.Fields.Item("linkfile").Value) & ">" & trim(Recordset2.Fields.Item("description").Value) & "</option>" %>


    <td width="231" height="25"> <select name="sendto" size="2" multiple class="blacktype" id="sendto">
            <% Response.write sendtomenu %>

2 个答案:

答案 0 :(得分:3)

您需要获得与此类似的标记:

<div id="CheckedListBox1" style="border-width:1px;border-style:Solid;height:100px;width:300px;overflow-y:scroll;padding:2px;">
    <input type="checkbox" id="cb1" /><label for="cb1">This is checkbox1</label><br>
    <input type="checkbox" id="cb2" /><label for="cb2">This is checkbox2</label><br>
    <input type="checkbox" id="cb3" /><label for="cb3">This is checkbox3</label><br>
    ... 
</div>

您很可能拥有动态列表(或可能是记录集)。你可以通过它循环。 您可以根据需要调整此解决方案。 (用任何值替换i。)

<div id="CheckedListBox1" style="border-width:1px;border-style:Solid;height:100px;width:300px;overflow-y:scroll;padding:2px;">
    <% For i = 1 To 10 %>
        <input type="checkbox" id=cb<% =i %> value=<% =i %> />
        <label for=cb<% =i %>>This is checkbox<% =i  %></label><br>
    <% Next %>
</div>

答案 1 :(得分:0)

要获取复选框列表,您应使用CheckedListBox控件。

aspx标记:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" BorderStyle="Solid" BorderWidth="1px" ></asp:CheckBoxList>

在代码隐藏中:

Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    '' this is the most simplest example of adding items. you may use databinding etc.
    CheckBoxList1.Items.Add("This is checkbox 1")
    CheckBoxList1.Items.Add("This is checkbox 2")
    CheckBoxList1.Items.Add("This is checkbox 3")
    CheckBoxList1.Items.Add("This is checkbox 4")
    CheckBoxList1.Items.Add("This is checkbox 5")
    CheckBoxList1.Items.Add("This is checkbox 6")
    CheckBoxList1.Items.Add("This is checkbox 7")
    CheckBoxList1.Items.Add("This is checkbox 8")
    CheckBoxList1.Items.Add("This is checkbox 9")
End Sub

要获取滚动条,您应将CheckedListBox括在Panel中,ScrollBars属性设置为Vertical

<asp:Panel ID="Panel1" runat="server" BorderStyle="Solid" BorderWidth="1px" ScrollBars="Vertical" Width="300px" Height="100px">
    <asp:CheckBoxList ID="CheckBoxList1" runat="server" ></asp:CheckBoxList>
</asp:Panel>