对象引用未设置为对象的瞬时 [英] object reference not set to instant of object

查看:48
本文介绍了对象引用未设置为对象的瞬时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...



我正在使用转发器控制..

内置转发器控制我有一个链接按钮和其他控件像radiobuttonlist和textboxes

我想编写代码就像用户点击转发器内的链接按钮一样,然后转发器内其他控件的所有值都应保存在某个地方



我在ItemCommand事件中编写了这段代码并访问其他控件,例如



Hi...

I am working with repeater control..
Inside repeater control I have a link button and other controls like radiobuttonlist and textboxes
I want to write code as if user click on link button inside repeater then all values fron other controls inside the repeater should be saved somewhere

I wrote this code in ItemCommand event and access other control like

Dim txtStart As TextBox = TryCast(e.Item.FindControl("txtdate"), TextBox)



ans访问其文本属性


ans accessing its text property as

Dim s As String = txtStart.Text





工作正常...



b当我访问其他控件如dropdownlist并使用其属性时它会给出异常

对象引用未设置为对象的瞬间





its working fine...

but as I access other control like dropdownlist and use its property it gives exception
object reference not set to instant of object

Dim ddlTenure As DropDownList = TryCast(e.Item.FindControl("drp1"), DropDownList)




Dim a As String=ddlTenure.SelectedItem.Text





请尽量解决

谢谢



please try to resolve
thanks

推荐答案

项目在下拉列表中不存在,因此它给出了错误。首先初始化下拉然后尝试执行代码。它会工作。



问候。
Item does not exists in the drop down list so it is giving an error. first initialize drop down then try to execute code. it will work.

Regards.


试试这个
Dim ddlTenure As DropDownList = DirectCast(e.Item.FindControl("drp1"), DropDownList)




Dim a As String=ddlTenure.SelectedValue



问候..


Regards..


检查你的项目名称: drp1是否存在?

如果确实如此,那么拆分你的行,并依次检查每个部分:

Check your item names: does "drp1" exist?
If it does, then split your lines, and check each part in turn:
Dim obj = e.Item.FindControl("drp1")

obj 等于 Nothing ?如果是双重检查名称!

如果没有,那么

Is obj equal to Nothing? If it is double check the name!
If not, then

Dim ddlTenure As DropDownList = TryCast(obj, DropDownList)

ddlTenure 等于 Nothing ?如果是,那么你需要检查下拉列表的实际类型并更正它。

最后,检查 ddlTenure.SelectedItem Nothing - 如果没有选择,那将是你的问题。

Is ddlTenure equal to Nothing? If it is, then you need to check the actual type of the dropdown and correct that.
Finally, check ddlTenure.SelectedItem against Nothing - if there is nothing selected, that will be your problem.


这篇关于对象引用未设置为对象的瞬时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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