实体类绑定网格后,网格标题如何显示该属性相应的中文???
实体类绑定网格后,网格标题如何显示该属性相应的中文???举例:
public cust: class,....(其它接口)
{
...
public string cust_id
{
get {...};
set {...};
};
public string cust_name
{
get {...};
set {...};
};
};
当把这个cust绑定到GridView后,cust_id列的标题如何设为"客户代号"呢???
--------------------编程问答-------------------- 没看明白。
是不是要:
public override string ToString()
{
return cust_name;
} --------------------编程问答-------------------- --------------------编程问答-------------------- GridView1.Columns[0].HeaderText="客户代号";
--------------------编程问答-------------------- 假如你要把Name属性显示为姓名
你要这样写
[CategoryAttribute("基础设定"),
DescriptionAttribute("控件的名字,必须为唯一,不区分大小写"),
ShowChinese("名称")]
public string Name
{
get
{
return name;
}
set
{
if (value == "" || value == null)
{
throw new Exception("Name 不可以为空值.");
}
if (name != value)
{
string temp=value;
if (Page != null)
{
temp = this.Page.CreateName(value, this.ID);
}
this.OnChanging();
name = temp;
this.OnChanged();
}
}
}
然后重写两个类
public class BasePropertyDescriptor : PropertyDescriptor
{
private PropertyDescriptor basePropertyDescriptor;
public BasePropertyDescriptor(PropertyDescriptor basePropertyDescriptor)
: base(basePropertyDescriptor)
{
this.basePropertyDescriptor = basePropertyDescriptor;
}
public override bool CanResetValue(object component)
{
return basePropertyDescriptor.CanResetValue(component);
}
public override Type ComponentType
{
get
{
return basePropertyDescriptor.ComponentType;
}
}
public override string DisplayName
{
get
{
string svalue = "";
foreach (Attribute attribute in this.basePropertyDescriptor.Attributes)
{
if (attribute is ShowChinese)
{
svalue = attribute.ToString();
break;
}
}
if (svalue == "") return this.basePropertyDescriptor.Name;
else return svalue;
}
}
public override string Description
{
get
{
return this.basePropertyDescriptor.Description;
}
}
public override object GetValue(object component)
{
object obj = basePropertyDescriptor.GetValue(component);
return obj;
}
public override bool IsReadOnly
{
get
{
return this.basePropertyDescriptor.IsReadOnly;
}
}
public override string Name
{
get
{
return this.basePropertyDescriptor.Name;
}
}
public override Type PropertyType
{
get
{
return this.basePropertyDescriptor.PropertyType;
}
}
public override void ResetValue(object component)
{
this.basePropertyDescriptor.ResetValue(component);
}
public override bool ShouldSerializeValue(object component)
{
return this.basePropertyDescriptor.ShouldSerializeValue(component);
}
public override void SetValue(object component, object value)
{
this.basePropertyDescriptor.SetValue(component, value);
}
}
[AttributeUsage(AttributeTargets.Property)]
public class ShowChinese : System.Attribute
{
private string sChineseChar = "";
public ShowChinese(string sChineseChar)
{
this.sChineseChar = sChineseChar;
}
public string ChineseChar
{
get
{
return this.sChineseChar;
}
}
public override string ToString()
{
return this.sChineseChar;
}
}
补充:.NET技术 , C#