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
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

for my Datareader

Then I have:

Code:
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

for my radiobutton- I'm trying to get a value from the database and populate the radiobuttonlist with it to show what the user previously selected-- Any ideas????
It's not working...

Thanks...
 
Any luck looking at this code? It's still not working-- I just want to populate the radio button for the value that corresponds in the DB- if the value is 100 then show the "Completed" as the selected Value, if it's 200 enable the "In progress" radiobutton, etc...
 
Did you trace through your code? I see you are using findbytext, I would suggest using findbyvalue. Your text comparison could be wrong.
 
Yes, I'm not even sure why you have FindByText in the full code behind that you listed. In all previous posts you have never mentioned this and have always referred to FindByValue. This could very well be the reason why it isn't working.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
I did try both-- neither work... Could it be the Datareader and the way it's configured?
 
I got it to work... I did:

Code:
If Result("currentStatus") = 100 Then
                    CurrentStatus.SelectedValue = 100
                ElseIf Result("currentStatus") = 200 Then
                    CurrentStatus.SelectedValue = 200
                Else
                    CurrentStatus.SelectedValue = 300
                End If

Thanks for all of your help... I do appreciate your time.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top