• ASP.NET 两个Dropdownlist控件联动


    两个dropdownlist联动网上代码很多,原理也很简单,这里不再重复了,贴下我自己的代码,希望对给位有帮助(主要关联是在第一个dropdownlist空间的selectindexchanged事件)

    第一个控件绑定:

    Private Sub display()
    Dim cmd As New DataBean ‘我是用的数据库连接类
    Dim ds As New DataSet
    Dim i As Integer
    Dim str As String = "SQL语句"

    cmd.ConnOracle()
    ds = cmd.GetDataSet(str)
    cmd.CloseConn()


    If ds.Tables(0).Rows.Count > 0 Then
    Me.drpplant.Items.Add("")
    For i = 0 To ds.Tables(0).Rows.Count - 1
    Me.drpplant.Items.Add(ds.Tables(0).Rows(i).Item(0).ToString)
    Next
    Else
    Me.lblMsg.Text = "Not Found Any Plant Data!"
    End If

    Me.btnstop.Enabled = False
    Me.List1.Items.Clear()
    Me.List2.Items.Clear()
    End Sub

    第二个控件内容绑定
    Private Sub downlocation(ByVal plant As String)
    Dim cmd As New DataBean
    Dim ds As New DataSet
    Dim i As Integer
    Dim str As String = "select wiplocation from cpi_wip_location where plant='" & plant & "' order by id asc"

    cmd.ConnOracle()
    ds = cmd.GetDataSet(str)
    cmd.CloseConn()

    If ds.Tables(0).Rows.Count > 0 Then
    For i = 0 To ds.Tables(0).Rows.Count - 1
    Me.drploc.Items.Add(ds.Tables(0).Rows(i).Item(0).ToString)
    Next
    End If

    End Sub

    第一个空间的联动事件:

    Protected Sub drpplant_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpplant.SelectedIndexChanged
    Me.drploc.Items.Clear()
    Call downlocation(Me.drpplant.SelectedValue.ToString.Trim)
    End Sub

  • 相关阅读:
    IntelliJ IDEA 快捷键大全
    springboot整合jsp 遇到的问题
    mysql数据库中某字段一部分乱码
    Spring-boot整合Redis,遇到的问题
    遍历对象和数组的forEach函数
    获取随机数,要求长度一致的字符串格式
    获取yyyy-mm-dd格式的日期
    JS对象常用API
    数组常用API
    JS中异步和单线程
  • 原文地址:https://www.cnblogs.com/kevinhome/p/2730397.html
Copyright © 2020-2023  润新知