佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1067|回复: 2

怎样可以dynamic dim object type 在 .NET

[复制链接]
发表于 21-8-2009 10:56 AM | 显示全部楼层 |阅读模式
对不起因为我在别的网站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 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 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 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 5-12-2025 01:36 PM , Processed in 0.115957 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表