469,631 Members | 1,126 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Display Property Name and Value

Any help on the follwing would be great.

If i have a business object like the folliwng

Object Name : Customer

PropertyName Value
FirstName John
LastName Smith
Address1 123 st. Name
Address2 Apt. 1234
City Bever Hill
State Ca
Zip 12399
Phone 111-111-1111
Job devleoper
Location LA
AGE 27
Skill Dotnet

I am trying to display all these properties in a text box
Is there any easy way to display the propertyname as well as teh value?

I am doing it like this presently

dispTxtBx.Text = "FirstName: " + customer.FirstName;
dispTxtBx.Text = "LastName: " + customer.LastName;
dispTxtBx.Text = "Address1: " + customer.Address1;
dispTxtBx.Text = "Address2: " + customer.Address2;

if the object has too many properties assigned to it very difficult to
display everything.

The above object is just an sample, the object i have is complex than
I wan to create something like the watch window probably.

Any easy way to to display the property name as well as the value?

Any help would be great.

Nov 17 '05 #1
2 1696
public string GetAllProperties(Object obj)
StringBuilder sb = new StringBuilder();
foreach (PropertyInfo pi in obj.GetType().GetProperties())
sb.AppendFormat("{0}: {1}\n", pi.Name, pi.GetValue(obj, null));
return sb.ToString();

Nov 17 '05 #2

Thank you so much, works great.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by endus | last post: by
10 posts views Thread by DettCom | last post: by
19 posts views Thread by dmiller23462 | last post: by
7 posts views Thread by jez123456 | last post: by
4 posts views Thread by drew197 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.