Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am comparing a value and on the basis of that i want to display/show a string in listview
e.g. for id 243 is must show job type field job else workshop job.

listview lable taking result as per id but not displaying on page properly,
but it only shows field job. both id 234 and 244 showing same result as field job

What I have tried:

Protected Sub joblistview1_ItemDataBound(sender As Object, e As ListViewItemEventArgs) Handles joblistview1.ItemDataBound
    Dim lbljobtype As Label = CType(e.Item.FindControl("JobTypeLabel"), Label)
    'Dim lbljobtype As Label = CType(joblistview1.FindControl("JobTypeLabel"), Label)
    ' Dim jobtypelist As ArrayList = New ArrayList()
    'Dim jobtypelist As List(Of String)
    'Dim jobtype As String()
    'jobtypelist = New List(Of String)

    Dim jobtypelist(ds.Tables(0).Rows.Count - 1) As String
    Dim i As Integer
    For i = 0 To ds.Tables(0).Rows.Count - 1
        jobtypelist(i) = ds.Tables(0).Rows(i)("CardTypeRefId")
        If jobtypelist(i) = 243 Then
            lbljobtype.Text = "Field Job"
        ElseIf jobtypelist(i) = 244 Then
            lbljobtype.Text = "Workshop Job"

        End If
    Next
End Sub
Posted
Updated 9-Aug-18 1:10am
v2
Comments
FranzBe 9-Aug-18 7:33am    
It is not clear to me, what you intend to do. You are iterating through all rows of a table and then assigning a single label text property dependent on the value of the CardTypeRefId field. The label will always hold the text corresponding to the id value of the last row before the loop exits.
[no name] 9-Aug-18 7:44am    
but it couldn't holding the value was supplied.. It is printing same result for both id's. it only shows field job. both id 234 and 244 showing same result as field job. I don't understand what's a problem?
CHill60 9-Aug-18 7:57am    
It briefly holds "Field Job" then when you move on to the next row that text is replaced by "Workshop Job" ... you only have one label to cover all of the rows in the table. Either add a column to the table or use a collection of labels.
[no name] 9-Aug-18 8:20am    
how can add a column to the table or use a collection of labels ?
FranzBe 9-Aug-18 8:26am    
SELECT
    <other fields>
    ,CardTypeRefId	   
    CASE WHEN  CardTypeRefId = 243 THEN 'Field Job'
         WHEN  CardTypeRefId = 244 THEN 'Workshop  Job'
         ELSE 'unknown'
    END AS JobDescription
FROM <Table>	

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900