I have the follow lines of code:
Protected Sub RepComisiones_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles RepComisiones.ItemDataBound
Dim valoresRepeter As DataRowView
If e.Item.ItemType = ListItemType.Item Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
valoresRepeter = e.Item.DataItem
Select Case valoresRepeter("ECO").ToString
Case "0"
CType(e.Item.FindControl("lblEco"), Label).Text = ""
End Select
Select Case valoresRepeter("A").ToString
Case 0
CType(e.Item.FindControl("lblA"), Label).Text = ""
End Select
Select Case valoresRepeter("B1").ToString
Case 0
CType(e.Item.FindControl("lblB1"), Label).Text = ""
End Select
Select Case valoresRepeter("B2").ToString
Case 0
CType(e.Item.FindControl("lblB2"), Label).Text = ""
End Select
Select Case valoresRepeter("B3").ToString
Case 0
CType(e.Item.FindControl("lblB3"), Label).Text = ""
End Select
Select Case valoresRepeter("B3P").ToString
Case 0
CType(e.Item.FindControl("lblB3P"), Label).Text = ""
End Select
End If
End Sub
I want to reduce some lines, I try diferent ways but the result is not correct, any idea how can I optimize.
Thank you
A simple and clean solution would be to put all keys ("ECO", "A", "B1") and their corresponding control names ("lblECO", "lblA", "lblB") in a dictionary and iterate through this for evaluating the individual conditions.
Private mappings As New Dictionary(Of String, String) From
{
{"ECO", "lblEco"},
{"A", "lblA"},
{"B1", "lblB1"}
}
Sub RepComisiones_ItemDataBound()
For Each key As String In mappings.Keys
If valoresRepeter(key).ToString Is "0" Then
DirectCast(e.Item.FindControl(mappings.Item(key)), Label).Text = ""
End If
Next
End Sub
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments