我想要使用發送給SetSectorImage子的Sector變量來命名正在更改的圖像(圖像確實已存在於Web表單上,我只是更改了URL)。谷歌搜索只讓我在MSDN上的一篇關於CallByName方法的文章,但我不知道它是否會在這種情況下發揮作用,我不知道它是如何工作的。如何在不知道ID的情況下更改圖片的屬性?
這裏的文章,如果有幫助:http://msdn.microsoft.com/en-us/library/22x2chfx.aspx
Imports System
Imports System.IO
Public Class Launcher
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SetSectorImage("Sector1")
SetSectorImage("Sector2")
SetSectorImage("Sector3")
End Sub
Sub SetSectorImage(Sector As String)
Dim SectorStatus As String
Try
Using Reader As New StreamReader(Sector + ".txt")
SectorStatus = Reader.ReadToEnd()
Reader.Close()
Sector_SHOULD_BE_USED_HERE.ImageUrl = ("~/Images/" + SectorStatus)
End Using
Catch ex As Exception
ErrorMessage.Text = ("There was an error reading the status of: " + Sector)
ErrorMessage.Visible = True
End Try
End Sub
End Class
訪問他們,我相信有一些像'Page.FindById(Sector)' –