|登录 |注册

查看: 1302|回复: 7
打印 上一主题 下一主题

疑问:谁能帮我缩短这些代码@@

[复制链接]
死神之神
2009-8-2 06:03 PM
While dr.Read
                If Button22.Text = dr("place_id").ToString Then
                    Button22.Enabled = False
                End If
                If Button21.Text = dr("place_id").ToString Then
                    Button21.Enabled = False
                End If
                If Button20.Text = dr("place_id").ToString Then
                    Button20.Enabled = False
                End If
                If Button19.Text = dr("place_id").ToString Then
                    Button19.Enabled = False
                End If
                If Button18.Text = dr("place_id").ToString Then
                    Button18.Enabled = False
                End If
                If Button17.Text = dr("place_id").ToString Then
                    Button17.Enabled = False
                End If
                If Button16.Text = dr("place_id").ToString Then
                    Button16.Enabled = False
                End If
                If Button15.Text = dr("place_id").ToString Then
                    Button15.Enabled = False
                End If
                If Button14.Text = dr("place_id").ToString Then
                    Button14.Enabled = False
                End If
                If Button13.Text = dr("place_id").ToString Then
                    Button13.Enabled = False
                End If
                If Button12.Text = dr("place_id").ToString Then
                    Button12.Enabled = False
                End If
                If Button11.Text = dr("place_id").ToString Then
                    Button11.Enabled = False
                End If
                If Button10.Text = dr("place_id").ToString Then
                    Button10.Enabled = False
                End If
                If Button9.Text = dr("place_id").ToString Then
                    Button9.Enabled = False
                End If
                If Button8.Text = dr("place_id").ToString Then
                    Button8.Enabled = False
                End If
                If Button7.Text = dr("place_id").ToString Then
                    Button7.Enabled = False
                End If
                If Button6.Text = dr("place_id").ToString Then
                    Button6.Enabled = False
                End If
                If Button5.Text = dr("place_id").ToString Then
                    Button5.Enabled = False
                End If
                If Button4.Text = dr("place_id").ToString Then
                    Button4.Enabled = False
                End If
                If Button3.Text = dr("place_id").ToString Then
                    Button3.Enabled = False
                End If
                If Button2.Text = dr("place_id").ToString Then
                    Button2.Enabled = False
                End If
                If Button1.Text = dr("place_id").ToString Then
                    Button1.Enabled = False
                End If
Super-Tomato
2009-8-2 06:40 PM
原帖由 死神之神 于 2009-8-2 06:03 PM 发表
While dr.Read
                If Button22.Text = dr("place_id").ToString Then
                    Button22.Enabled = False
                End If
                If Button21.Text = dr("place_ ...



使用 Array 的方式循環就可以縮減判斷, 如  Button(i).Text
死神之神
2009-8-2 07:23 PM
那该怎么做
我试过用array了可是不成功
zechs
2009-8-2 08:18 PM
原帖由 死神之神 于 2009-8-2 07:23 PM 发表
那该怎么做
我试过用array了可是不成功


可不可以放code看看,还是你试试看用while loop来做。
叛逆志文
2009-8-11 11:18 PM
If Button <23.Text = dr("place_id").ToString Then
                    Button <23.Enabled = False
                End If

可不可以这样子?
我不懂的,用猜的..

回复 #3 死神之神 的帖子

宅男-兜着走
2009-8-11 11:48 PM
22 个btn 用for loop 来循环应该是可以的。

回复 #5 叛逆志文 的帖子

宅男-兜着走
2009-8-11 11:51 PM
你觉得呢?当然不可以
goodday
2009-8-12 10:31 PM
我懒哦
4 行搞定


               For i As Integer = 1 To 22
            Dim bt As String = "Button" + i.ToString()
            If CType(Panel1.FindControl(bt, True), Button) = dr("place_id").ToString() Then
           dim btnow as new button = CType(Panel1.FindControl(bt, True), Button)
btnow.enable = true;
end if
        Next

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

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2025-3-11 06:29 AM , Processed in 0.100008 second(s), 27 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部