I have class called GroupSelect and made a collection List(Of GroupSelect)().
Now I need to find GroupSelect with RowNo and GroupNo in List(Of GroupSelect)(). If I found at same index update Value. If not found add to List(Of GroupSelect).
Public Class GroupSelect
Public Property RowNo() As Integer
Get
Return m_RowNo
End Get
Set(ByVal value As Integer)
m_RowNo = value
End Set
End Property
Private m_RowNo As Integer
Public Property GroupNo() As Integer
Get
Return m_GroupNo
End Get
Set(ByVal value As Integer)
m_GroupNo = value
End Set
End Property
Private m_GroupNo As Integer
Private m_Value As Integer
Public Property Value() As Integer
Get
Return m_Value
End Get
Set(ByVal value As Integer)
m_Value = value
End Set
End Property
End Class
Find this Object in the colleaction
grpSelect.RowNo = rowNo
grpSelect.GroupNo = grpNo
grpSelect.Value = CType(CType(row.FindControl("txtCombine"),
TextBox).Text, Integer)
How to do this?
Assuming collection is your
List(Of GroupSelect)andRowNo,GroupNoare the values you are checking againt andValueis the new valueSingleOrDefault()should be ideal in your case because it doesn’t look like you will never have more than one item matching the criteria. But it might be a good idea to surround the query with withTry..Catch.