下拉选定项,将数据从数据库显示到面板中的复选框列表中

时间:2019-01-09 08:05:32

标签: sql asp.net vb.net

关于我的项目,我需要一些帮助。 我在面板中有下拉列表和一个复选框列表。选择下拉列表项后,我想将数据库中的数据显示到复选框列表中。

This is the dropdownlist that will change the data in the panel based on the selected item

|---- Please Select -----|
|  Orange                |
|  Red                   |
|  Yellow                |
|________________________|


This panel with the checkbox next to the item that will be display from database after choosing the red from dropdownlist.
 __________________________
|                          |
|      [] Apple            |
|      [] Strawberry       |
|      [] Dragonfruit      |
|__________________________|

从下拉列表中选择一项后,我不知道如何在面板中显示数据。这是我已经完成的一些代码。

<div class="form-group">
    <label class="col-sm-2 control-label2 no-padding-right" for="form-field-1"><span style="color: red">*</span>Colour </label>                                                                                      
    <div class="col-sm-6">
        <asp:DropDownList ID="ddlColour" runat="server" Width="330px" AutoPostBack="true" OnSelectedIndexChanged="ddlColour_SelectedIndexChanged"></asp:DropDownList>
    </div> 
</div>
<div class="form-group">   
    <label class="col-sm-2 control-label2 no-padding-right" for="form-field-1"><span style="color: red">*</span>Fruits </label>
    <div class="col-sm-6">
        <asp:UpdatePanel ID="UpdatePanelSkill" runat="server">
            <ContentTemplate>
               <asp:Panel ID="pnlFruits" runat="server" ScrollBars="Vertical" Width="400px" Height="150px" BorderStyle="Solid" BorderColor="Black" BorderWidth="1px">
                  <asp:CheckBoxList ID="chkFruits" class="list-group-item" AutoPostBack ="true" runat="server" Width="95%">
                  </asp:CheckBoxList>
               </asp:Panel>  
            </ContentTemplate>
        </asp:UpdatePanel>                                 
    </div>
    <div>
        <asp:Button runat="server" ID="btnAddFruits" Text="Add" />
        <asp:Literal runat="server" ID="lblFruits"></asp:Literal>
    </div>
</div>

Public Sub GetFruits(ByVal sender As Object)
    attPage.SQLQuery = DC.Data_SupermarketItems("111", ddlColour.SelectedItem.Value)
    DS = DA.GetSQLDataset(attPage.SQLQuery)
    If DS IsNot Nothing AndAlso DS.Tables(0).Rows.Count > 0 Then
        Dim row As DataRow
        For Each row In DS.Tables(0).Rows
            Dim Name As String
            Dim ID As Integer
            Name = row("FruitsName").ToString
            ID = row("FruitID")
            chkFruits.Items.Add(New ListItem(Name, ID.ToString))
        Next
    End If
End Sub

Protected Sub ddlColour_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlColour.SelectedIndexChanged
    If ddlColour.SelectedIndex > 0 Then
        GetFruits(ddlColour.SelectedItem.Value)
    End If
End Sub

从下拉列表中选择颜色后,我执行的代码未显示水果列表。谁能帮我吗?

0 个答案:

没有答案