【问题标题】:CheckBox List from dynamic values来自动态值的复选框列表
【发布时间】:2015-11-10 07:16:02
【问题描述】:

我正在用 VB 编写一个经典的 ASP 页面,这两个页面我都不太熟悉。我正在尝试改变这个

到这里

这应该很简单,除了它看起来像列表是动态的并且它绊倒我。

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

【问题讨论】:

  • 您具体遇到了什么问题?
  • 我不知道如何将我拥有的东西变成更像这样的东西
    这是复选框
    这是复选框
    这是复选框
    这是复选框
    这是复选框
    这是复选框
    这是复选框
    跨度>
  • 感谢您的反对,一些信息将是最有帮助的
  • 你的标签是自相矛盾的:这是asp.net(和vb.net),还是asp-classic(和vbscript)?

标签: html vbscript asp-classic


【解决方案1】:

你需要得到类似这样的标记:

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

【讨论】:

    【解决方案2】:

    要获取复选框列表,您应该使用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>
    

    【讨论】:

    • 谢谢,因为这是经典的 asp,我不确定是否可以使用 asp 控件。
    • 好吧..你把vb.net和classic-asp标签都放了,这很混乱。我将添加经典的asp解决方案。
    猜你喜欢
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2020-06-22
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    相关资源
    最近更新 更多