Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radiobuttonlist - get value from SQL DB

Status
Not open for further replies.

tsp1lrk72

IS-IT--Management
Feb 25, 2008
100
US
Hi-

I have this code:

Code:
        If Not Page.IsPostBack Then
            'Define connection to read the data 
            Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
            Dim MyCmd As New SqlCommand("SELECT [VendorID],[DivisionName],[DeptName],[VendorName],[VendorCode],[CurrentStatus],[Joined],[SKU],[EDI],[RBT],[ContactName],[ContactPhone],[ContactFax],[EmailAddress]FROM [ENAPTEST].[dbo].[tblVendorInfo] Where VendorID =  @VendorID", myConn)
            MyCmd.CommandType = CommandType.Text
            MyCmd.Parameters.Add(New SqlParameter("@VendorID", SqlDbType.Int, 4)).Value = Convert.ToString(VendorID)
            myConn.Open()
            'Read the data
            Dim Result As SqlDataReader = MyCmd.ExecuteReader(CommandBehavior.CloseConnection)
            Result.Read()
            VendorNumber.Text = Result("VendorID").ToString()

            If Not Result.IsDBNull(0) Then
                DivisionName.Text = Result("DivisionName").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                DeptName.Text = Result("DeptName").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                VendorName.Text = Result("VendorName").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                VendorCode.Text = Result("VendorCode").ToString()
            End If
            
            If Not Result.IsDBNull(0) Then
                Joined.Text = Result("Joined").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                SKU.Text = Result("SKU").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                EDI.Text = Result("EDI").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                RBT.Text = Result("RBT").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                ContactName.Text = Result("ContactName").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                ContactPhone.Text = Result("ContactPhone").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                ContactFax.Text = Result("ContactFax").ToString()
            End If
            If Not Result.IsDBNull(0) Then
                EmailAddress.Text = Result("EmailAddress").ToString()
            End If

Here is the code for the radiobutton:

Code:
            'CurrentStatus.SelectedValue = Result("CurrentStatus").ToString()

            Dim radList As RadioButtonList
            radList = CType(FindControl("CurrentStatus"), RadioButtonList)
            Do While Result.Read()
                Dim CurrentSelect As ListItem
                CurrentSelect = radList.Items.FindByValue(Result("CurrentStatus").ToString())
                If Not CurrentSelect Is Nothing Then
                    CurrentSelect.Selected = True
                End If
            Loop

            myConn.Close()
        End If

I'm trying to retrieve a value from a SQL table using a datareader to populate the radiobuttonlist with that value so when they edit their data, they can see what they previously chose... but this is producing nothing- any ideas???
Thanks...
When I write Result("CurrentStatus").ToString I get the value of 300 which is "In Progress" so I want to show that in the radiobuttonlist, it's coming up blank,not pulling anything from the db...
 
First, you are posting in the the wrong forum, the question should be posted here: forum855

Second, nowhere in your code are you binding the list to anything and nowhere are you adding listitems to the radiobutton list.
 
It's VB.Net code, why is it the wrong forum?
 
Because this is an ASP.NET question. The control you are using does not exist in VB.NET, it is ASP.NET specific. Also, when using ASP.NET, the language is irrelevant. If you were using C#, you would not post in that forum either.
 
It's not a problem. I was just pointing you in the right direction, because you may have not gotten a response since this control is specific to ASP.NET
 
I understand... Thanks very much, I appreciate it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top