DropDownList1_SelectedIndexChanged-的使用

DropDownList1_SelectedIndexChanged-的使用怎样使当DropDownList1改变时也改变相应的DropDownList2的值?实现二级联动。如省市联动啊。以下有代码。将DropDownList1的AutoPostBack属性设为true导入命名空间ImportsSystem.DataImportsSystem.Data.SqlClientPrivateSubPage_Load(ByValsen

大家好,又见面了,我是你们的朋友全栈君。

怎样使当DropDownList1改变时也改变相应的DropDownList2的值?
实现二级联动。如省市联动啊。
以下有代码。
将DropDownList1的AutoPostBack属性设为true

导入命名空间
Imports System.Data
Imports System.Data.SqlClient

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
'Dim mydb As DB
If Not IsPostBack Then
'绑定省
'Dim connstr As String = "server=.;database=mag_Web;User ID=sa;password=;"
'Dim myconn As SqlConnection
'myconn = New SqlConnection(connstr)
'myconn = mydb.GetSqlconn()
Dim myconn As SqlConnection = myconnection.GetSqlconn
myconn.Open()
Dim mycommand As New SqlCommand("select * from province", myconn)
Dim myreader As SqlDataReader
myreader = mycommand.ExecuteReader()
DropDownList1.DataSource = myreader
DropDownList1.DataTextField = "proName"

DropDownList1.DataValueField = "proID"
DropDownList1.DataBind()
myreader.Close()
'绑定市
Dim mycity As New SqlCommand("select * from city where proID=" + DropDownList1.SelectedValue, myconn)
Dim myreader1 As SqlDataReader
myreader1 = mycity.ExecuteReader()
DropDownList2.DataSource = myreader1
DropDownList2.DataTextField = "cityName"
DropDownList2.DataValueField = "cityID"
DropDownList2.DataBind()
myreader1.Close()
myconn.Close()
End If
'Dim myconn As SqlConnection

End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
txtUserName.Text = ""
txtPassword1.Text = ""
txtPassword2.Text = ""
RequiredFieldValidator1.Visible = False And RequiredFieldValidator2.Visible = False
'CompareValidator1.Visible = False

End Sub

Private Sub btnSumbit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSumbit.Click
'Dim connstr As String = "server=.;database=mag_Web;User ID=sa;password=;"

Dim myconn As SqlConnection = myconnection.GetSqlconn
'myconn = New SqlConnection(connstr)
myconn.Open()
Dim mycommand As New SqlCommand("insert into mag_Users(UserName,UserPassword,UserProvince,UserCity) values('" + txtUserName.Text + "','" + txtPassword1.Text + "','" + DropDownList1.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Text + "')")
mycommand.Connection = myconn
mycommand.ExecuteNonQuery()
myconn.Close()
Response.Redirect("Login2.aspx")

End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim proID As String
proID = DropDownList1.SelectedValue
'Dim connstr As String = "server=.;database=mag_Web;User ID=sa;password=;"
Dim myconn As SqlConnection = myconnection.GetSqlconn
'myconn = New SqlConnection(connstr)
'myconn = mydb.GetSqlconn()
myconn.Open()
Dim mycommand As New SqlCommand("select * from city where proID=" + proID, myconn)
Dim myreader As SqlDataReader
myreader = mycommand.ExecuteReader()
DropDownList2.DataSource = myreader
DropDownList2.DataTextField = "cityName"

DropDownList2.DataValueField = "cityID"
DropDownList2.DataBind()
myreader.Close()
myconn.Close()

End Sub
 

其他回答

将DropDownList1的AutoPostBack属性设为true

在DropDownList1_SelectedIndexChanged 中
将DropDownList1.SelectedValue 赋给DropDownList2

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/161259.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • APP爬虫技术总结

    APP爬虫技术总结APP常用抓包技术-工具Charles,fiddler,burpsuite,PacketCapture等,具体操作可以查找百度-抓包方法 a.常规操作直接抓 b.使用Xposed+JustTrustMe关闭SSL证书验证抓包关闭SSL证书校验之前抓包

    2022年5月11日
    53
  • JS一维数组转化为三维数组有这个方法就够了

    JS一维数组转化为三维数组有这个方法就够了一个方法搞定 js 一维数组转化三维数组

    2025年8月23日
    3
  • 推荐一款神仙颜值的 Redis 客户端工具

    推荐一款神仙颜值的 Redis 客户端工具日常开发过程中,项目常常都会使用Redis来做缓存或者Session服务器,为了更直观方便,开发者常常会使用一些可视化工具,如RedisDesktopManager、RedisClent等,但界面UI做得不尽人意,作为当今时代,对软件的UI还是有所期待的,今天给大家分享一款,高颜值、功能强大的Redis客户端工具。AnotherRedisDesktopMan…

    2025年11月21日
    6
  • pycharm虚拟环境下安装第三方库_pycharm需要配置环境变量吗

    pycharm虚拟环境下安装第三方库_pycharm需要配置环境变量吗pycharm配置虚拟环境安装虚拟环境1.安装相关库pipinstallvirtualenv2.切换到python安装目录下,创建虚拟环境virtualenv虚拟环境名(可自定义)virtualenvvenv3.进入cd到虚拟环境的位置(目录)的Scripts中,激活(activate.bat)虚拟环境cdvenv\Scripts#激活虚拟环境activate.bat4.退出虚拟环境deactivate.batdeactivate.bat5.使用在p

    2022年8月28日
    9
  • jenkins教程菜鸟_jenkins新手入门教程

    jenkins教程菜鸟_jenkins新手入门教程Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。虽然jenkins提供了Window、Linux、OSX等安装程序,但是都没有war方便。本文用的是jenkins的war包,简单、方便、快捷。一、安装jenkins1.在https://jenkins.io/下载jenkins.war;##…

    2022年5月14日
    48
  • android studio输出文字_androiditem长按删除

    android studio输出文字_androiditem长按删除用EditText实现textView长按复制效果,edittexttextview首先EditText是集成TextView的我们直接将?EditText设置为不可编辑来实现其中重点为:android:background=”@null”//背景设为null,去掉editText下划线android:textCursorDrawable=”@null”//游标设为null,去掉游…

    2022年9月29日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号