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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value Drop Down List from Database Value

Status
Not open for further replies.
Mar 1, 2001
37
US
I have a drop down list that with values of Full-Time and Part-Time. My database field stores these values as F and P respectfully. So when I grab the data from my database, it is returning an F or a P. How can I display the "Full-Time" index when the database returns a "F" and display the "Part-Time" index when the database returns a "P"? I was hoping to do something such as
If Not IsDBNull(dr.Item("Enrollment")) Then
Me.ddlEnrollment.SelectedIndex = CType(dr.Item("Enrollment"), String)
End If

Thanks.
 
Is your question that you want to display Full-time instead of F and part-time instead of P? Also, how are you retreiving the values from the dB, are you using a stored procedure or a select statment from .net?
 
Yes, this is what I'm trying to do. Since the Full-Time and Part-Time are already in the drop-down list, I just want to have it display one of the two depending on if a F or P is returned from the DB. I am using a select statement and a data reader to get the values.
 
Not sure how you are adding values to the drop down, but you can try this:

Code:
If <your data reader>.Item(<column to check) = "P" Then
   DropDownList1.Items.Add("Part-Time")
Else
   DropDownList1.Items.Add("Full-Time")
End IF
 
The only problem with doing this is that these values are already in the drop down list and if I do an Items.Add, they will be in there twice. I need both of them in the list because the user will be able to change it if they want.
 
The ddlEnrollment drop down is databound and filled from a table by a dataset. So the values in the Drop Down should always be "Full-Time" or "Part-Time".

The user can click an Add button which will store this information (but as an F or P) along with other fields in a separate table.

All this works good. The problem arises when the user wants to view this information (or pull it down from the database it was just added to). Somehow I just need the drop down to display Full-Time instead of "F".
 
You are confusing me.. first you said datareader then you said dataset. I am not following you. if you can, please post your code behind.
 
'Enrollment
Dim Enrollment As New SqlParameter("@Enrollment", SqlDbType.Char, 1)
Enrollment.Value = Me.ddlEnrollment.SelectedItem.Value
updLoanCertProfile.Parameters.Add(Enrollment)


Sub Enrollment()
Me.sscEnrollment = New System.Data.SqlClient.SqlCommand
Me.sdaEnrollment = New System.Data.SqlClient.SqlDataAdapter
Me.dsEnrollment = New LoanCertification.dsEnrollment

Me.sscEnrollment.CommandText = "SELECT CodeTableKey, CodeTableValue, CodeTableTrID FROM CodeTable WHERE (CodeTabl" & _
"eName = 'Enrollment')"
Me.sscEnrollment.Connection = Me.scLoan

Me.sdaEnrollment.SelectCommand = Me.sscEnrollment
Me.sdaEnrollment.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "CodeTable", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("CodeTableKey", "CodeTableKey"), New System.Data.Common.DataColumnMapping("CodeTableValue", "CodeTableValue"), New System.Data.Common.DataColumnMapping("CodeTableTrID", "CodeTableTrID")})})
End Sub



Sub GetProfileValues()
Dim dr As SqlDataReader
Dim cmd As New SqlCommand

cmd.CommandText = "SELECT ProfileName, LoanPeriodBeginDate, LoanPeriodEndDate, Enrollment, GradeLevel, GraduationDate, " & _
"EstimatedCostAmt, FinancialAidAmt, PrivateLoanAmt, SubStaffordAmt, UnsubStaffordAmt, " & _
"PLUSAmt, Disbursement1HoldReleaseFlag, Disbursement1Date, Disbursement2HoldReleaseFlag, Disbursement2Date, " & _
"Disbursement3HoldReleaseFlag, Disbursement3Date, Disbursement4HoldReleaseFlag, Disbursement4Date " & _
"FROM LoanCertificationProfile lcp Inner JOIN " & _
"School s ON lcp.SchoolTrID = s.SchoolTrID Inner JOIN " & _
"UsersSchool us on s.SchoolTrID = us.SchoolTrID Inner JOIN " & _
"Users u on us.UsersTrID = u.UsersTrID " & _
"WHERE (u.UsersTrID = " & Me.strUsersTrId & ") and ProfileName = '" & Me.ddlLoanCertProfile2.SelectedItem.Text & "'"

cmd.CommandType = CommandType.Text
Me.scLoan.Open()
cmd.Connection = Me.scLoan
dr = cmd.ExecuteReader()

If dr.Read Then


'If Not IsDBNull(dr.Item("Enrollment")) Then
' Me.ddlEnrollment.Items. = CType(dr.Item("Enrollment"), String)
'End If



End If

Me.scLoan.Close()

End Sub
 
You can loop throug the dropdown list and replace the text:
Code:
Dim i, ddlcnt As Integer
ddlcnt = DropDownList1.Items.Count
For i = 0 To ddlcnt - 1
   If <Your DropDownList>.Items(i).Text = "P" Then
      <Your DropDownList>.Items(i).Text = "Part-Time" 
   ELSE
      <Your DropDownList>.Items(i).Text = "Full-Time"
   End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top