Avatar of sherbug1015
Flag for United States of America asked on

Setting a Public Property with a variable.

I have a Class with several properties called Priority1, Priority2,Priority3....through Priority11  Each has a Get/Set construct

 Public Property Priority1 As Integer
            Return pPriority1
        End Get
        Set(value As Integer)
            pPriority1 = value
        End Set
    End Property

When saving from my code behind, I want to set the property with a variable something like this:

                For i = 1 To 11
                    ti = "txtPriority" & i
                    Dim li = "Priority" & i
                    tb = DirectCast(RowItem.Cells(1).FindControl(ti), TextBox)
                    lRefactoring.li = tb.Text  **** This is the line that is not working

Is there anyway to set the property with a variable?  

Thank you for any help.
ASP.NETVisual Basic.NETC#

Avatar of undefined
Last Comment

8/22/2022 - Mon
Meir Rivkin

use this function to set object property by its name:

sedwick:  Do I only need to set the PropertyName parameter?
Meir Rivkin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Be aware that the method overload of GetProperty(String) is case-sensitive. You will need to pass the name of the property to the propertyName variable exactly how it is written (with respect to character casing) in your class; otherwise, the property will not be found.

The first parameter to that function is the instance of the class for which you want to set a value on its property (e.g. tb); the second is the name of the property you want to set; the third is the value you want to set for that property.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Thank you.  I have it working now.  Much appreciated.