|
查看: 1068|回复: 2
|
怎样可以dynamic dim object type 在 .NET
[复制链接]
|
|
|
对不起因为我在别的网站type 的很多,也不懂要如何用 话语解释,希望版主可以通融一下我参英文来发文和解释 :handshake:
for each xxx as web.ui.control in contentplaceholder.controls
Dim bbb as xxx.gettype() <--- got error
bbb = xxx
bbb.visible = false
...
...
next
p/s: because XXX can be textbox , label , chekcbox... any kind of webcontrol
i wish to dim a temporary object as same type as the xxx then assign the xxx to the temporary then only i can access it property like label control got text property , check box got chekced property....
current my alternative solution is
for each xxx as web.ui.control in contentplaceholder.controls
select case true
case if typeof(xxx) = label then
dim tempcontrol as lable
tempcontrol = ctype( xxx , label)
if tempcontrol.attribute("SGrounp") = "group1" then
tempcontrol.visible = "false"
End if
case if typeof(xxx) = textbox then
dim tempcontrol as textbox
tempcontrol = ctype( xxx , textbox)
if tempcontrol.attribute("SGrounp") = "group1" then
tempcontrol.visible = "false"
End if
case if typeof(xxx) = gridview then
dim tempcontrol as gridview
tempcontrol = ctype( xxx , gridview )
if tempcontrol.attribute("SGrounp") = "group1" then
tempcontrol.visible = "false"
End if
........
End select
next
in web page there are can be any kind of web control like panel , check box , table, dropdownlist ......
no way i can use so many select case to cater all kind of web control type
that is why i wish can do soemthing like
for each xxx as web.ui.control in contentplaceholder.controls
dim tempcontrol as typeof (xxx)
tempcontrol = ctype( xxx , typeof (xxx))
if tempcontrol.attribute("SGrounp") = "group1" then
tempcontrol.visible = "false"
End if
next
but i not able to dim a tempcontrol with dynamically when see what the xxx control is
dim an tempcontrol as typrof(XXX)
dim an tempcontrol as XXX.getype()
有什么方法么?
[ 本帖最后由 bee002 于 21-8-2009 11:39 AM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 23-9-2009 10:13 PM
|
显示全部楼层
关于你第一个 error [gettype],当然你只可以把他们 cast 去 web.ui.controls,因为那是 base class。
过后,通过 looping 每个 control,才来看它的 gettype 是不是你要的 control。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 3-10-2009 12:13 PM
|
显示全部楼层
其实要gettype不难, 最大的问题是要如何跟据gettype时拿到的control type 来dim 一个新的object... 不想用 select case 一个个来matching
=〉 dim tempcontrol as typeof (xxx)
不过还是谢谢你的帮忙其实我已经找到解决方法了。
[ 本帖最后由 bee002 于 3-10-2009 12:14 PM 编辑 ] |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|