asp.net列表框问题 [英] asp.net listbox problem

查看:56
本文介绍了asp.net列表框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中有Asp.net Listbox Control。

这是内容page.suppose我正在使用表单它会正常工作。但是使用内容页面列表框不起作用。 />
现在我在我的代码中使用:

dim getitem as string = listbox1.selecteditem.tostring()。

但我有错误作为对象参考没有设置为对象的实例。

如何解决这个问题......

In my application having Asp.net Listbox Control.
and this is content page.suppose i am using form it will work fine.but using content page the list box is not work.
now i used in my code:
dim getitem as string=listbox1.selecteditem.tostring().
but i have got error as Object reference not set to an instance of an object.
how can i solve this problem...

推荐答案

让我们假设 listbox1 不为空。因此,问题发生是因为没有选择列表框项目;在这种情况下 listbox1.SelectedItem 为null;你试图通过使用 ToString 取消引用空引用,这会给你这个例外。



请始终运行你的在问这样的问题之前,调试器下的代码。如果你这样做,你会立即看到问题。通常,每次对运行时行为都有一点关注时,请始终使用调试器。







请查看我过去的答案我在相关问题上编写了几个过去的答案,源代码示例适用于 ComboBox ListBox

combobox.selectedvalue显示{}在winform中 [ ^ ]。



-SA
Let''s assume listbox1 is not null. So, the problem happens because none of the list box items is selected; in this case listbox1.SelectedItem is null; you are trying to dereference null reference by using ToString, which gives you this exception.

Please always run your code under debugger before asking questions like this one. If you did, you would see the problem immediately. Generally, always use the debugger every time you have a slightest concern about your run-time behavior.



Please see my past answer where I complied several past answers on related problems, with source code samples applicable to ComboBox and ListBox:
combobox.selectedvalue shows {} in winform[^].

—SA


这篇关于asp.net列表框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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