How can I optimize the code

navarend

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

Dennis Kassel

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I optimize this code to print in this format?

From Dev

How can I optimize this code with ARM NEON?

From Dev

How can i optimize my Jquery code?

From Dev

how i can optimize this java code?

From Dev

How can I optimize this android code?

From Dev

How can I optimize This Code Into Lesser Line of Code

From Dev

How can I optimize my code for my Spanish Translation Program?

From Dev

How can I optimize my EF Code First query?

From Dev

How can I optimize my Two Sums code in Python?

From Dev

How can i optimize cycles?

From Dev

How can i optimize this regex?

From Dev

How can I optimize the 'IN' query?

From Dev

How can I optimize my code to answer the path numbers I can go from A to B?

From Java

Is there any way I can optimize this R code?

From Dev

Can I Optimize this code with better array manipulation?

From Dev

Can I use a loop to optimize my code?

From Dev

How can I optimize this code for creating TIFF files and/or what alternate libraries should I consider to improve performance?

From Dev

How can I optimize my code such that I am able to use a loop to plot histograms in subplots?

From Dev

How could I optimize the following piece of code?

From Dev

How do I optimize this simple matlab code?

From Dev

How can I fix and optimize this very simple piece of "Game of Life" code by taking advantage of NumPy's functionality?

From Dev

How can I optimize my code for generating a pseudorandom String for high speed in Java?

From Dev

How can I optimize my code for Swapping the array elements of given range of indexes with related element?

From Dev

How can I optimize my code for generating a pseudorandom String for high speed in Java?

From Dev

How can I optimize the code current algorithm take O(n+m+k)?

From Dev

HackerRank Python - some test cases get "Terminated due to timeout", how can i optimize the code?

From Dev

How can I optimize my code in a way where only one method is required (if possible)?

From Dev

How can I optimize javascript assets?

From Dev

How can I optimize active_admin

Related Related

  1. 1

    How can I optimize this code to print in this format?

  2. 2

    How can I optimize this code with ARM NEON?

  3. 3

    How can i optimize my Jquery code?

  4. 4

    how i can optimize this java code?

  5. 5

    How can I optimize this android code?

  6. 6

    How can I optimize This Code Into Lesser Line of Code

  7. 7

    How can I optimize my code for my Spanish Translation Program?

  8. 8

    How can I optimize my EF Code First query?

  9. 9

    How can I optimize my Two Sums code in Python?

  10. 10

    How can i optimize cycles?

  11. 11

    How can i optimize this regex?

  12. 12

    How can I optimize the 'IN' query?

  13. 13

    How can I optimize my code to answer the path numbers I can go from A to B?

  14. 14

    Is there any way I can optimize this R code?

  15. 15

    Can I Optimize this code with better array manipulation?

  16. 16

    Can I use a loop to optimize my code?

  17. 17

    How can I optimize this code for creating TIFF files and/or what alternate libraries should I consider to improve performance?

  18. 18

    How can I optimize my code such that I am able to use a loop to plot histograms in subplots?

  19. 19

    How could I optimize the following piece of code?

  20. 20

    How do I optimize this simple matlab code?

  21. 21

    How can I fix and optimize this very simple piece of "Game of Life" code by taking advantage of NumPy's functionality?

  22. 22

    How can I optimize my code for generating a pseudorandom String for high speed in Java?

  23. 23

    How can I optimize my code for Swapping the array elements of given range of indexes with related element?

  24. 24

    How can I optimize my code for generating a pseudorandom String for high speed in Java?

  25. 25

    How can I optimize the code current algorithm take O(n+m+k)?

  26. 26

    HackerRank Python - some test cases get "Terminated due to timeout", how can i optimize the code?

  27. 27

    How can I optimize my code in a way where only one method is required (if possible)?

  28. 28

    How can I optimize javascript assets?

  29. 29

    How can I optimize active_admin

HotTag

Archive