首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

类型“String”的值无法转换为“System.Web.UI.WebControls.DropDownList”怎么处理

2012-01-09 
类型“String”的值无法转换为“System.Web.UI.WebControls.DropDownList”怎么办imiAsIntegerDimddls(10)AsDr

类型“String”的值无法转换为“System.Web.UI.WebControls.DropDownList”怎么办
im   i   As   Integer
                Dim   ddls(10)   As   DropDownList
                Dim   aaa   As   String
                '   遍历Form1种的所有控件,从中找出所有的DropDownList控件,只要是DropDownList的控就存入ddls()数组中
                For   Each   ctrl   As   Control   In   Me.Form.Controls
                        aaa   =   ctrl.GetType.ToString
                        If   ctrl.GetType.ToString   =   "System.Web.UI.WebControls.DropDownList "   Then
                                ddls(i)   =   ctrl.Id     '这里出错   类型“String”的值无法转换为“System.Web.UI.WebControls.DropDownList”
                                i   +=   1
                        End   If
                Next

[解决办法]
or

ddls(i) =CType(ctrl,System.Web.UI.WebControls.DropDownList)

[解决办法]
那您应该另外定义一个string数组来存,但是这个没有,到时您没办法用这些名字来遍历这些控件的,其实您可以在第一次遍历控件找到DropDownList时就对其赋值,这样直接一点,也方便一点。您要是要的话,我可以写一下。

热点排行