从动态BindingList获取值 [英] Get Values from dynamic BindingList

查看:86
本文介绍了从动态BindingList获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我有一个BindingList< dynamic>我希望循环并使用下面的代码获取值,我在一些示例中找到但是PropertyInfo值pi返回null。



任何帮助表示赞赏



Hi
I have a BindingList<dynamic> that I wish to loop through and obtain the values using the code below which I found in some examples but the PropertyInfo value pi is returning null.

Any assistance appreciated

var planData = (BindingList<dynamic>)Session["fgtPlanData"];
foreach (var pdat in planData)
{
    PropertyInfo pi = pdat.GetType().GetProperty("CompanyId");
    var gCell = pi.GetValue(pdat);
}

推荐答案

嗨forestgrove,



按照您的代码发布将有两个案例,为什么你从null获得null

Hi forestgrove,

As per your code posted there will be two case why you are getting null from
PropertyInfo pi = pdat.GetType().GetProperty("CompanyId");





1.没有任何与CompanyId名称相关的财产。

2.如果有名称为CompanyId的财产那么它不公开。



由于Type.GetProperty()方法只返回带有提供名称的公共属性。


这篇关于从动态BindingList获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆