问题运行页面 [英] problem wher running page
问题描述
大家好,
我在dropdownlist数据绑定事件上写了以下代码
下拉列表的ID为"dupddatedist"
Hello all,
i have the following code thad i write on the dropdownlist databound event
the ID of dropdown list is"dupddatedist"
Protected Sub dupddatedist_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddupdatedist.DataBound
Dim ddl As DropDownList = DirectCast(sender, DropDownList)
'add an empty item on top of the list
AddEmptyItem(ddl)
Dim frmV As FormView = DirectCast(ddl.NamingContainer, FormView)
'If frmV.DataItem IsNot Nothing Then
'Let's pull the province value from the databound item. The data
'in my application is supplied by BLL as a dataview. Therefore each
'item bound to the FormView is of type DataRowView. So let's cast
'that DataItem to the appropriate type to be able to use it
Dim intDistrict As Int32 = DirectCast(frmV.DataItem, DataRowView)("intContactPerson1DistrictID")
ddl.ClearSelection()
'be careful of the possibility that the value saved on the
'database does not exist in the valid selections that are displayed
'on the list
Dim li As ListItem = ddl.Items.FindByValue(intDistrict)
If li IsNot Nothing Then
li.Selected = True
End If
但是当我运行代码时,出现以下错误
从"DBNull"类型到"Integer"类型的转换无效.
请帮我知道我该怎么做
并为该问题编写正确的代码
谢谢和问候
Subiya ahsan
but when i run the code i got following error
Conversion from type ''DBNull'' to type ''Integer'' is not valid.
please help me out what shoul i do
and also write the correct code for the problem
Thanks and regards
Subiya ahsan
推荐答案
该探针最有可能在此行上:
Most likely the probelm is on this line:
Dim intDistrict As Int32 = DirectCast(frmV.DataItem, DataRowView)("intContactPerson1DistrictID")
在设置变量的值之前,请检查该变量是否不包含数据库中的null(在.Net中为DbNull.Value).有关示例,请参阅: http://msdn.microsoft.com/en-us/library/system.dbnull.aspx [ ^ ]
Before setting the value of the variable, check that it doesn''t contain a null from database, which would be a DbNull.Value in .Net. For an example, see: http://msdn.microsoft.com/en-us/library/system.dbnull.aspx[^]
这篇关于问题运行页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!