现在有类using System;
using System.Collections.Generic;
using System.Text;
using System.Data;namespace test
{
    public class Class1
    {
        private string _test;
        private int _able;
        private float _test2;
        private string _test3;
        private string _test4;
        private string _test5;
        private double _test6;        public string test4
        {
            get { return _test4; }
            set { _test4 = value; }
        }        public string test5
        {
            get { return _test5; }
            set { _test5 = value; }
        }        public double test6
        {
            get { return _test6; }
            set { _test6 = value; }
        }        public string test
        {
            get { return _test; }
            set { _test = value; }
        }        public int able
        {
            get { return _able; }
            set { _able = value; }
        }        public float test2
        {
            get { return _test2; }
            set { _test2 = value; }
        }        public string test3
        {
            get { return _test3; }
            set { _test3 = value; }
        }
    }
}
这样的类有很多个,请问怎样将里面的属性获取出来显示在页面上(ASP.NET),并能够编辑这些属性,点击某一属性时显示属性的说明,类似WINFROM中PropertyGrid这样的东西
做过这样东西的人给点思路,谢谢!

解决方案 »

  1.   

    [Bindable(true), Category("自定义"), NotifyParentProperty(true),Description("test3")]
    public string test3
            {
                get { return _test3; }
                set { _test3 = value; }
            }
      

  2.   

    [Description("test3"), Category("自定义"), Browsable(true)]
        public string test3
            {
                get { return _test3; }
                set { _test3 = value; }
            }
      

  3.   

    如果你要在程序中自己写代码并显示某个类的属性的话,使用反射技术。参考下面的代码        public class Class1
            {
                private string _test;
                private int _able;
                private float _test2;
                private string _test3;
                private string _test4;
                private string _test5;
                private double _test6;            public string test4
                {
                    get { return _test4; }
                    set { _test4 = value; }
                }
                public string test5
                {
                    get { return _test5; }
                    set { _test5 = value; }
                }
                public double test6
                {
                    get { return _test6; }
                    set { _test6 = value; }
                }
                public string test
                {
                    get { return _test; }
                    set { _test = value; }
                }
                public int able
                {
                    get { return _able; }
                    set { _able = value; }
                }
                public float test2
                {
                    get { return _test2; }
                    set { _test2 = value; }
                }
                public string test3
                {
                    get { return _test3; }
                    set { _test3 = value; }
                }
            }
            
            protected void Page_Load(object sender, EventArgs e)
            {
                Class1 obj = new Class1();
                System.Type type = obj.GetType();
                PropertyInfo[] piPublicArray = type.GetProperties();
                Response.Write("<b>类名:"+ type.Name+"</b><br>");
                Response.Write("共有" + piPublicArray.Length + "个公有属性");
                foreach (PropertyInfo pi in piPublicArray)
                {
                    object val = pi.GetValue(obj, null);
                    Response.Write("<li>"+pi.Name + "&nbsp值:"+ (val==null?"null":val.ToString())  +"</li>");
                }            FieldInfo[] piNonpublicArray = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
                Response.Write("<br>共有" + piNonpublicArray.Length + "个非公有字段");
                foreach (FieldInfo fi in piNonpublicArray)
                {
                    object val = fi.GetValue(obj);
                    Response.Write("<li>" + fi.Name + "&nbsp值:"+ (val==null?"null":val.ToString())+  "</li>");
                }
            }
      

  4.   

    你这个显示在页面上是指.aspx文件还是.cs文件?
    cs文件好像可以直接NEW出来