怎样才能使用相同的code线属性描述符获得两个控件的值? [英] How can Property Descriptor gets values of two controls using same code line?
问题描述
我发现这个code通过自定义GridView的自定义控制,工作正常的前雇员开发的项目之一,但我不知道它究竟是干什么的,
code
公共类aBoundField:的ImageField
{
//这里我定义了一些被置属性
保护覆盖无效OnDataBindField(对象发件人,EventArgs的)
{
控制控制=(控制)发送;
的PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer))查找(绑定列,真正的)。
。的PropertyDescriptor propertyB = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer))查找(绑定列,真正的);
PropertyAFieldValue = this.GetValue(control.NamingContainer,this._PropertyAField,裁判propertyA)的ToString();
PropertyBFieldValue = this.GetValue(control.NamingContainer,this._PropertyBField,裁判propertyB)的ToString();
base.OnDataBindField(发件人,E);
}
这是怎么回事在 OnDataBindField
方法,尤其是当它被越来越的PropertyDescriptor。我做了一点研究,想通了,这是一个属性包,但如果它是一个属性包它如何知道是物业A或物业B在此code什么样的价值。
的PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer))查找(绑定列,真正的);
。的PropertyDescriptor propertyB = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer))查找(绑定列,真正的);
什么我完全不明白的是
如何属性描述获得使用相同的code线的两个控制值
<$p$p><$c$c>TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField",真正)
如何将高于code线会找出如果物业A和物业B点。
我就先想着它的属性包从一个属性描述符值,但它并没有正常工作。
的GetValue(control.NamingContainer,this._PropertyAField,裁判propertyA)
ProperyA是作为为此所发生的一切,以propertyA的方法内上面定义将更新propertyA一个参考。
使用
的PropertyDescriptor propertyA = NULL;
而不是
的PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer))查找(绑定列,真正的);
仍然可以工作。
进一步阅读
裁判方法参数关键字
I found this code in one of the project developed by an Ex-Employee for custom gridview with custom controls which works fine but I am not sure what exactly it is doing,
CODE:
public class aBoundField : ImageField
{
//here I got some get set properties defined
protected override void OnDataBindField(object sender, EventArgs e)
{
Control control = (Control)sender;
PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true);
PropertyDescriptor propertyB = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true);
PropertyAFieldValue = this.GetValue(control.NamingContainer, this._PropertyAField, ref propertyA).ToString();
PropertyBFieldValue = this.GetValue(control.NamingContainer, this._PropertyBField, ref propertyB).ToString();
base.OnDataBindField(sender, e);
}
What's happening in OnDataBindField
method especially when it is getting PropertyDescriptor. I did bit research and figured out that it is a property bag, but if it is a property bag How would it know what value is for property A or Property B in this code.
PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true);
PropertyDescriptor propertyB = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true);
What I don't exactly understand is
How can Property Descriptor gets values of two controls using same code line
TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true)
How would above code line will figure out if its for Property A or Property B.
I tried to get values from one property descriptor thinking its a property bag but it didn't worked properly.
GetValue(control.NamingContainer, this._PropertyAField, ref propertyA)
ProperyA is given as a reference therefor everything that happens to propertyA inside that method will update propertyA that was defined above.
using
PropertyDescriptor propertyA = null;
instead of
PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true);
will still work.
Further Reading
ref method parameter keyword
这篇关于怎样才能使用相同的code线属性描述符获得两个控件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!