Link to home
Start Free TrialLog in
Avatar of sherbug1015
sherbug1015Flag 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
        Get
            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
       Next

Is there anyway to set the property with a variable?  

Thank you for any help.
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

use this function to set object property by its name:
http://www.devx.com/vb2themax/Tip/19599
Avatar of sherbug1015

ASKER

sedwick:  Do I only need to set the PropertyName parameter?
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Thank you.  I have it working now.  Much appreciated.