Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamically default selected item of a dropdown control in vb.net

Posted on 2008-10-30
2
Medium Priority
?
589 Views
Last Modified: 2012-05-05
Hello,
This was put in a class file (say the name is GenericClass.vb)
 
   Dim sqlConn As OracleConnection

    'fill Level ID COMBO BOXES
    Public Sub LevelId(ByRef ddlLvlIdFrom As DropDownList)
        Try
            sqlConn = ConnectionManager.GetNewConnection()

            Using sqlConn
                Dim command As OracleCommand = New OracleCommand("SELECT DEPTID FROM DEPT ORDER BY DEPTID", sqlConn)
                sqlConn.Open()
                Dim reader As OracleDataReader = command.ExecuteReader()

                If reader.HasRows Then
                    Do While reader.Read()
                    ddlLvlIdFrom.Items.Add(reader(0).ToString)     'ddlLvlIdFrom name of the dropdown              
                    Loop
                End If

                reader.Close()
            End Using
           Finally
            If Not (sqlConn Is Nothing) Then
                sqlConn.Close()
            End If
        End Try
    End Sub
   
    The query above retrieves data as :
   
    0000
    1234
    1345
    2111
   
Another funtion in the same class is:
 
 Public Function GetUserInfo(ByVal str As String) As String
         Dim ret As String = Nothing
 
         Try
             sqlConn = ConnectionManager.GetNewConnection()
 
             Dim sql As String = "SELECT D.DEPTID, E.AENM FROM EMP E, DEPT D" & _
                                 " WHERE E.ID = D.ID AND E.SYSNAME ='mamun'"
                 Using sqlConn
                 sqlConn.Open()
                 Dim oraCmd As OracleCommand = New OracleCommand(Sql, sqlConn)
                 Dim reader As OracleDataReader = oraCmd.ExecuteReader()
                 Dim strLevel As String = ""
                 Dim strName As String = ""
 
                 If reader.Read Then
                     If str = "LEVEL" Then ret = reader.GetString(0)
                     If str = "NAME" Then ret = reader.GetString(1)
                 End If
                 reader.Close()
             End Using
 
         Finally
             If Not (sqlConn Is Nothing) Then
                 sqlConn.Close()
             End If
         End Try
 
         Return ret
 
    End Function
   
This query returns:

1111      John Doe
1345      Mamun
2111      Plumber John

Now, in the page load event of the page1.aspx, when I display the contents of the page, I want to set the default selected value of the drop down box to be based on the user information obtained from the windows login.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      Dim obj As New GenericClass        
        obj.LevelId(ddlLvlIdFrom) 'here I want to show the default to be selected mine which is 1345 and the rest of the data
   
   End Sub
   

How can I call the GetUserInfo for the dropdown control to show the default values selected? Any ideas will be appreciated.

I am trying to convert vb 6.0 app to ASP.NET app.

Thanks
mamun
0
Comment
Question by:mamunahmed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 total points
ID: 22849414
Are you able to obtain the user info already? If the question is just how to select the value then there are a couple of ways.

cbxUsers.SelectedIndex = cbxUsers.FindString("User Name")

cbxUsers.SelectedValue = "Value"

etc
0
 

Author Closing Comment

by:mamunahmed
ID: 31511900
I had to change the GetUserInfo function and added another parameter as argument. Such as:
Public Function GetUserInfo(ByVal username As String, ByVal str As String) As String

Then used the suggested solution.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question