我写了一个函数是这样的
[code]
Protected Function checknull(ByVal list As String(), ByVal sw As Boolean) As Boolean
If list.Length <> 0 Then
Dim obj As New Object
Dim i As Integer
Dim flag As Boolean = False
If sw = True Then
For i = 0 To list.Length - 1
obj = FindControl(list(i))
If TypeOf obj Is TextBox Then
If CType(obj, TextBox).Text = "" Then
Return False
End If
ElseIf TypeOf obj Is DropDownList Then
If CType(obj, DropDownList).SelectedValue = CStr(0) Then
Return False
End If
End If
Next
Return True
Else
For Each obj In Controls(1).Controls
For i = 0 To list.Length - 1
---问题出在这里--------- If obj = list(i) Then ----------------------------
flag = True
End If
Next
If flag = False Then
If TypeOf obj Is TextBox Then
If CType(obj, TextBox).Text = "" Then
Return False
End If
ElseIf TypeOf obj Is DropDownList Then
If CType(obj, DropDownList).SelectedValue = CStr(0) Then
Return False
End If
End If
End If
Next
Return True
End If
End If
End Function[/code]看我上面画线的地方,提示说在option strict on 的时候不允许后期绑定。obj是一个object,而且不知道他在页面上显示的时候是什么类型,所以没法用ctype进行类型转换呀。大家帮忙想想办法。给个解决方案。
[code]
Protected Function checknull(ByVal list As String(), ByVal sw As Boolean) As Boolean
If list.Length <> 0 Then
Dim obj As New Object
Dim i As Integer
Dim flag As Boolean = False
If sw = True Then
For i = 0 To list.Length - 1
obj = FindControl(list(i))
If TypeOf obj Is TextBox Then
If CType(obj, TextBox).Text = "" Then
Return False
End If
ElseIf TypeOf obj Is DropDownList Then
If CType(obj, DropDownList).SelectedValue = CStr(0) Then
Return False
End If
End If
Next
Return True
Else
For Each obj In Controls(1).Controls
For i = 0 To list.Length - 1
---问题出在这里--------- If obj = list(i) Then ----------------------------
flag = True
End If
Next
If flag = False Then
If TypeOf obj Is TextBox Then
If CType(obj, TextBox).Text = "" Then
Return False
End If
ElseIf TypeOf obj Is DropDownList Then
If CType(obj, DropDownList).SelectedValue = CStr(0) Then
Return False
End If
End If
End If
Next
Return True
End If
End If
End Function[/code]看我上面画线的地方,提示说在option strict on 的时候不允许后期绑定。obj是一个object,而且不知道他在页面上显示的时候是什么类型,所以没法用ctype进行类型转换呀。大家帮忙想想办法。给个解决方案。
解决方案 »
- asp.net母版中的图片显示到子页面。
- 请教一个正则表达式的写法
- 提取html的src和href的值
- 跨页面取值查询问题
- 请问如何实现FormView 在删除记录前提示 谢谢!
- 急!急!急!如何在页面初始化的时候设置窗口的大小,和隐藏地址栏??
- 同学去面试的两个面试题!
- 求人才招聘网的整站代码 [email protected] asp asp.net 都行 能用就行,老板让找的
- 关于一个页面上用两个不同的自定义验证控件来验证两组文本框!!!
- DataGrid & Excel problem
- 有关datalist及radioButtonList
- 大家讨论一下,在学.net一定程度厚(可以做简单的电子商务)下一步怎么发展呢?
...
If obj1.ID = list( i) Then
正解,这办法其实早该想到,呵呵。谢谢兄弟/姐妹解答!