SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Location
    forest of dean UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    listbox with two fields together

    I'm going for gold tonite here's another question

    I want to pull to fields into a listbox, but I don't want them on seperate lines I need them to be together e.g PART_NUMBER & PART_DESCRIPTION so every line in the list box shows the part number & part description together

    Any ideas?

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably the easiest way to do this is just build the prodId + prodDesc string in the sql.

    How you output the select depends on whether you want to use the resulting RS or not. Below I've included a function that takes a 2D array and writes the select. The array is created with the RS method GetRows.

    Code:
    'Declare variable that'll be 2 dimensional array to hold recordset values
    Dim arrResults
    
    'Assuming that you've created connection & recordset
    'objects
    
    strSQL = "SELECT prodID, (prodID + ' ' + prodDesc) AS [Description]"
    
    objRecordset.Open strSQL, objConn
    
    If Not objRecordset.EOF Then
        arrResults = objRecordset.GetRows(-1)
    End If
    
    If IsArray(arrResults)
        'Write html select
        DisplaySelect(arrResults, "product", "")
    End If
    
    
    SUB DisplaySelect(arrValues, sSelectID, sSelectedValue)
    
    Dim bValid
    Dim sValue
    Dim sDisplayText
    Dim x
    Dim intRowDim
    
    	'Check input data
    	If IsArray(arrValues) Then
    		
    		Response.Write "<select name=""" & sSelectID & """"
    		Response.Write " id=""" & sSelectID & """>" & vbCrLf
    		intRowDim = UBOUND(arrValues,2) 
    		For x=0 to intRowDim
    		
    			bValid = True
    			sValue = Trim(arrValues(0,x))
    			sDisplayText = Trim(arrValues(1,x))
    			
    			'Check for nulls or blanks
    			If IsNull(sValue) Or IsNull(sDisplayText) Then
    				bValid = False
    			ElseIf (sValue = "") Or (sDisplayText = "") Then
    				bValid = False
    			End If
    			
    			If bValid Then
    				Response.Write "<option value=""" & sValue  & """"
    				If sValue = sSelectedValue Then
    					Response.Write " selected "
    				End If
    				Response.Write  ">" & sDisplayText & "</option>" & vbCrLf
    			End If
    				
    		Next
    		Response.Write "</select>" & vbCrLf
    	End If
    
    END SUB
    Last edited by shane; Jun 5, 2001 at 15:44.

  3. #3
    SitePoint Member
    Join Date
    Feb 2001
    Location
    forest of dean UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Shane I'll try it out and let you know

    Cheers Col.

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've realised that you'll probably have a problem with the sql I gave. If the id field is of type char/varchar you probably won't have any problems but if the id field is a numeric data type you'll have problems concatenating it.

    If you're using SQl Server try the following instead:
    SELECT prodID, (CONVERT(VARCHAR(10), prodID) + ' ' + prodDesc) AS [Description]

    If you're using Access try:
    SELECT prodID, (prodID & ' ' & prodDesc) AS [Description]


    You may also want to trim the description field depending upon the length.

  5. #5
    SitePoint Member
    Join Date
    Feb 2001
    Location
    forest of dean UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Shane I haven't had chance to try it yet, & I'm using access so I'll keep it in mind, I'll post back here if i get problems


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •