Home
Manage Your Code
Snippet: Set form values based on properties of object (VB.NET)
Title: Set form values based on properties of object Language: VB.NET
Description: Set the form values based on properties of object using reflection Views: 138
Author: Kevin Isom Date Added: 3/2/2008
Copy Code  
1Dim properties As PropertyInfo() = myClassInstance.[GetType]().GetProperties(BindingFlags.[Public] Or BindingFlags.Instance)
2
3Dim placeholder As ContentPlaceHolder = Me.Form.FindControl("ContentPlaceHolder1")'placeholder of a masterpage

4For Each prop As PropertyInfo In properties
5	Dim controlToSet As ITextControl = placeholder.FindControl(prop.Name)
6	If controlToSet IsNot Nothing Then 
7		Dim retValue = prop.GetValue(myClassInstance, Nothing)
8		controlToSet.Text = retValue 
9	End If
10Next
11