locked
DropDownList RRS feed

  • Question

  • User-49671077 posted

    I have the following code to fill dropdownlist:

    Dim strConn As String = ConfigurationManager.ConnectionStrings("connectionString").ConnectionString
            Using sqlConn As New SqlConnection(strConn)
                Using sqlCmd As New SqlCommand()
                    sqlCmd.CommandText = "SELECT departmentname FROM DepartmentMembership where sid='" & Session("empId") & "' order by ordby"
                    sqlCmd.Connection = sqlConn
                    sqlConn.Open()
                    Dim da As New SqlDataAdapter(sqlCmd)
                    Dim dt As New DataTable()
                    
                    da.Fill(dt)
                    EmpDept.DataSource = dt
    
                    EmpDept.DataValueField = "departmentname"
                    EmpDept.DataTextField = "departmentname"
                    EmpDept.DataBind()
                    sqlConn.Close()
                End Using
            End Using

    I want if dropdownlist is emply then show msgbox("Please add data")

    Thanks

    Wednesday, February 19, 2020 8:32 AM

Answers

  • User-49671077 posted

    Issue Solved..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 19, 2020 3:46 PM

All replies

  • User475983607 posted

    I want if dropdownlist is emply then show msgbox("Please add data")

    This requirement is not possible in a web application because the MsgBox will display on the web server not in the browser.   Anyway, you just need to write code that checks if the SQL results set is empty then prompt the user to add data using standard server controls.  For example a label.

    If you are building a Windows Application then you are in the wrong support forum.   

    Wednesday, February 19, 2020 2:05 PM
  • User-49671077 posted

    Thanks for reply..

    Is possible to insert word "Add data" in blank dropdownlist if it is empty? 

    Wednesday, February 19, 2020 2:42 PM
  • User-49671077 posted

    Issue Solved..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 19, 2020 3:46 PM