| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2470 人关注过本帖
标题:dropdownlist赋值问题
只看楼主 加入收藏
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
结帖率:97.66%
收藏
 问题点数:0 回复次数:3 
dropdownlist赋值问题
<asp:DropDownList ID="depNo" runat="server" Width="160px" AutoPostBack="True" />
要怎么把MSSQL的值塞进depNo这个控件里?

SQL查询命令:
Dim mySQL As String = "SELECT DepartmentNo, DepartmentName FROM tblMstDepartment Where DepartmentNo Like '72%' And DeptLevelNo In (50, 80) Order By DepartmentNo"
搜索更多相关主题的帖子: dropdownlist 赋值 String SELECT FROM 
2017-05-25 18:22
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
程序代码:
Private Sub GetDepNo()
        Dim i As Integer = 0
        Dim mySQL As String = "SELECT DepartmentNo, DepartmentName FROM tblMstDepartment Where DepartmentNo Like '72%' And DeptLevelNo In (50, 80) Order By DepartmentNo"
        Try
            Using mySqlDS As SqlDataSource = New SqlDataSource
                mySqlDS.ProviderName = strDbType
                mySqlDS.ConnectionString = WebConfigurationManager.ConnectionStrings(strCnnType & "DbBTA").ConnectionString
                mySqlDS.SelectCommand = mySQL
                mySqlDS.DataSourceMode = SqlDataSourceMode.DataSet
                Dim my_args As New DataSourceSelectArguments
                Dim my_DV As Data.DataView = mySqlDS.Select(my_args)
                For i = 0 To my_DV.Count - 1 Step 1
                    depNo.Attributes.Add("", "") '???这边要怎么写???
                Next i
            End Using
        Catch ex As Exception
            Dim strErr As String = "●●● 程式错误讯息如下 ●●●" & "\n\n" & Replace(Replace(Replace(Replace(Trim(ex.ToString()), Chr(10), ""), Chr(13), ""), "\", "\\"), "'", "\'")
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('" & strErr & "');", True)
        End Try
    End Sub

不要選我當版主
2017-05-25 19:11
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
自己找出来了...

程序代码:
Private Sub GetDepNo()
        Dim dbCmdSQL As SqlCommand
        Dim mySQL As String = "SELECT DepartmentNo, DepartmentName FROM tblMstDepartment Where DepartmentNo Like '72%' And DeptLevelNo In (50, 80) Order By DepartmentNo"
        depNo.Items.Clear()
        depNo.Items.Add(New ListItem(""))
        Try
            Using mySqlDS = New SqlConnection(ConfigurationManager.ConnectionStrings(strCnnType & "DbBTA").ToString)
                dbCmdSQL = New SqlCommand(mySQL, mySqlDS)
                mySqlDS.Open()
                Using dbDRSQL = dbCmdSQL.ExecuteReader
                    While dbDRSQL.Read
                        Dim str As String = dbDRSQL("DepartmentNo").ToString & " " & dbDRSQL("DepartmentName").ToString
                        depNo.Items.Add(New ListItem(str))
                    End While
                End Using
            End Using
        Catch ex As Exception
            Dim strErr As String = "●●● 程式错误讯息如下 ●●●" & "\n\n" & Replace(Replace(Replace(Replace(Trim(ex.ToString()), Chr(10), ""), Chr(13), ""), "\", "\\"), "'", "\'")
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('" & strErr & "');", True)
        End Try
    End Sub

不要選我當版主
2017-05-26 10:58
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
连动也OK了...

程序代码:
Protected Sub depNo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles depNo.SelectedIndexChanged
        Dim DepNo As String = sender.SelectedValue : DepNo = Mid(DepNo, 1, 4)
        Dim dbCmdSQL As SqlCommand
        Dim mySQL As String
        UserNo.Items.Clear() : UserNo.Items.Add(New ListItem(""))
        ClassNo.Items.Clear() : ClassNo.Items.Add(New ListItem(""))
        Try
            mySQL = "SELECT EmployeeNo, EmployeeName FROM tblMstEmployee Where DepartmentNo = '" & DepNo & "' AND Active = 'Y'"
            Using mySqlDS = New SqlConnection(ConfigurationManager.ConnectionStrings(strCnnType & "DbBTA").ToString)
                dbCmdSQL = New SqlCommand(mySQL, mySqlDS)
                mySqlDS.Open()
                Using dbDRSQL = dbCmdSQL.ExecuteReader
                    While dbDRSQL.Read
                        Dim str As String = dbDRSQL("EmployeeName").ToString & " (" & dbDRSQL("EmployeeNo").ToString & ")"
                        UserNo.Items.Add(New ListItem(str))
                    End While
                End Using
            End Using

            mySQL = "SELECT ClassID, SubClassID, FileID FROM tblClassList"
            Using mySqlDS = New SqlConnection(ConfigurationManager.ConnectionStrings(strCnnType & "DbBTA").ToString)
                dbCmdSQL = New SqlCommand(mySQL, mySqlDS)
                mySqlDS.Open()
                Using dbDRSQL = dbCmdSQL.ExecuteReader
                    While dbDRSQL.Read
                        Dim str As String = GetClassName(0, dbDRSQL("ClassID").ToString, dbDRSQL("SubClassID").ToString, dbDRSQL("FileID").ToString)
                        ClassNo.Items.Add(New ListItem(str))
                    End While
                End Using
            End Using
        Catch ex As Exception
            Dim strErr As String = "●●● 程式错误讯息如下 ●●●" & "\n\n" & Replace(Replace(Replace(Replace(Trim(ex.ToString()), Chr(10), ""), Chr(13), ""), "\", "\\"), "'", "\'")
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('" & strErr & "');", True)
        End Try
    End Sub

不要選我當版主
2017-05-26 11:33
快速回复:dropdownlist赋值问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.067418 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved