如何获取下拉列表的选定值 [英] How to get the selected value of dropdownlist

查看:96
本文介绍了如何获取下拉列表的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello

i在我的asp项目中有2个DropdownList,第一个从SQL DB填充,另一个从SQL DB填充,但是基于第一个选择的值。 />
问题是当我从第二个DropdonList中选择值并点击保存时我什么都没有,所选项目什么都没有



注意:两者都是DropdownList位于Repeater Control中



我尝试过:



Hello
i have 2 DropdownList in my asp project and the first one is populated from SQL DB and the other one is populated from SQL DB but based on the selected value from the first one .
the problem is when i select the value from the second DropdonList and click on save i got nothing , the selected item is nothing

Note : both of DropdownList are Located into Repeater Control

What I have tried:

To Populate DropDownList i use the following :
Dim dr As System.Data.SqlClient.SqlDataReader
                        Dim iListItem8 As New ListItem
                        iListItem8.Value = -1
                        iListItem8.Text = ""
                        cmbFinish.Items.Add((iListItem8))
                        dr = FinishType.AS_GetAllFinishType("ID")
                        While dr.Read
                            Dim iListItem88 As New ListItem
                            iListItem88.Value = dr("ID")
                            iListItem88.Text = dr("FinishCode") & " - " & dr("Description")
                            cmbFinish.Items.Add((iListItem88))
                        End While
                        dr.Close()


'*************************************************
 Protected Sub cmbFinish_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
         Dim cmbFinish As DropDownList = CType(sender, DropDownList)
        Dim currentRow As RepeaterItem = CType(cmbFinish.NamingContainer, RepeaterItem)
        Dim cmbColor As DropDownList = CType(currentRow.FindControl("cmbColor"), DropDownList)
        If ((Not (cmbFinish) Is Nothing) AndAlso ((cmbFinish.SelectedIndex > 0) AndAlso (Not (cmbColor) Is Nothing))) Then
            Dim FinishID As String = cmbFinish.SelectedValue
            Dim dr As System.Data.SqlClient.SqlDataReader
            Dim iListItem9 As New ListItem
            iListItem9.Value = -1
            iListItem9.Text = ""
            cmbColor.Items.Add((iListItem9))
            dr = FinishColor.AS_GetAllFinishColorByFinishTypeID(FinishID)
            While dr.Read
                Dim iListItem99 As New ListItem
                iListItem99.Value = dr("ID")
                iListItem99.Text = ("ColorCode") & " - " & dr("Description")
                cmbColor.Items.Add((iListItem99))
            End While
            dr.Close()
        ElseIf (Not (cmbColor) Is Nothing) Then
            cmbColor.Items.Clear()
        End If

    End Sub

推荐答案

检查一下它们为您提供了明确的示例。

< a href =https://docs.microsoft.com/en-us/aspnet/web-forms/overview/ajax-control-toolkit/cascadingdropdown/using-cascadingdropdown-with-a-database-vb>使用CascadingDropDown广告atabase(VB)| Microsoft Docs [ ^ ]
Check this they give clear example for you.
Using CascadingDropDown with a Database (VB) | Microsoft Docs[^]


这篇关于如何获取下拉列表的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆