对象引用未设置为对象的实例.[关于项目数据绑定事件] [英] Object reference not set to an instance of an object.[On item databound event]
问题描述
错误:-
string status = Convert.ToString(((HiddenField)e.Item.FindControl("hfstatus")).Value);
对象引用未设置为对象的实例.
注意:-
在数据列表项数据绑定事件中,出现此错误.
在这里,如果我以前从隐藏字段"hfstatus"中检索值,
datalist1.DataSource = dt;
datalist1.DataBind();我能够获得价值.
但是为什么我无法读取控件(或)在项目数据绑定事件中从控件读取值.
谁能帮我解决这种情况...
预先感谢....
Object reference not set to an instance of an object.
Note : -
In datalist item databound event,i''m getting this error.
Here,if i used to retrieve the value from the hidden field ''hfstatus'' after,
datalist1.DataSource = dt;
datalist1.DataBind(); this i''m able to get the value.
But why i Can''t able to read the control (or) read the value from the control on item databound event.
Can anyone help me to solve this scenario...
Thankz in Advance....
推荐答案
(HiddenField)e.Item.FindControl("hfstatus")).Value;
返回一个空值.
放置一个断点并检查该值.
补充:您需要调试并找出返回空值的原因.
is returning a null.
Put a break point and check the value.
Added: You need to debug and find out the reason why it is returning a null.
更具体地说,我敢打赌FindControl()
返回空值,可能是因为控件名称区分大小写(或者您拼错了).
就像其他人所说的那样,将代码行放入try/catch
块中,并检查实际引发的异常.
More specifically, I betFindControl()
is returning null, probably because the control name is case-sensitive (or you misspelled it).
Like the other guy said, put the line of code into atry/catch
block and inspect the actual exception being thrown.
这篇关于对象引用未设置为对象的实例.[关于项目数据绑定事件]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!