Yeah, i dont know why dir.getFiles("*.gif,*.jpg") could not work but the checking of extension works fine. Right now, i wish to display the so called staffid (in this case image name without the extension) in the txtSearch control which is created in my webform and not .acsx (user control) file.
I dont know why when i first retrieve the id of the imgSelected control for the first time, it cannot display. I tried saving the value of the id in viewState() but still to no avail.
There were 2 types of methods i have tried, the first coding does not even return a id at all. The second method does but returns the id of image selected previously and not the current id of the image selected. For example, first image selected is id "1", the txtSearch will not display anything. When i click on another image which is id "2" will not be displayed. Instead image id "1" was displayed.
Code:
--First Method--
'Public Property staffId() As String
' Get
' Return viewState("staffid")
' End Get
' Set(ByVal Value As String)
' viewState("staffid") = Value
' End Set
'End Property
--Second Method --
Public ReadOnly Property staffId() As String
Get
Return txtURL.Text
End Get
End Property
Webform coding
Code:
Protected Image_UC As WebUserControl1
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
PlaceHolder1.Controls.Add(Image_UC)
Image_UC.folderPath = "E:\DIT\Year 3\BRCOM\Assignment\Web Project\BRCOM Assignment\Images"
txtStaffId.Text = Image_UC.staffId
End Sub
Those lines highlighted in red is where i assign the image id to the viewState() which is assigned to the textbox.
Code:
Protected Sub repImages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repImages.ItemDataBound
Dim Item As RepeaterItem = CType(e.Item, RepeaterItem)
Dim MyImage As New Image
Dim firstImg As Boolean
Dim fullFilePath As String
MyImage = Item.FindControl("imgItem")
Dim MyFileInfo As System.IO.FileInfo
'Earlier repImages databind System.IO.FileInfo,
'therefore need to convert repeater item to System.IO.FileInfo
MyFileInfo = CType(Item.DataItem, System.IO.FileInfo)
fullFilePath = strFolderPath & "\" & MyFileInfo.Name
If (Right(MyFileInfo.Name, 4) = ".gif") Or (Right(MyFileInfo.Name, 4) = ".jpg") Then
If (imgSelected.ImageUrl = "") Then
imgSelected.ImageUrl = strFolderPath & "\" & MyFileInfo.Name
'imgItem that was supposed to have image url of imageSelected
'will not be displayed.
MyImage.Visible = False
'strStaffId = MyFileInfo.Name.Split(".")(0)
viewState("staffid") = MyFileInfo.Name.Split(".")(0)
txtURL.Text = viewState("staffid")
Else
If (imgSelected.ImageUrl <> strFolderPath & "\" & MyFileInfo.Name) Then
MyImage.ImageUrl = strFolderPath & "\" & MyFileInfo.Name
Else
'selected image will not be visible in the asp:repeater
MyImage.Visible = False
'strStaffId = MyFileInfo.Name.Split(".")(0)
viewState("staffid") = MyFileInfo.Name.Split(".")(0)
txtURL.Text = viewState("staffid")
End If
End If
Else
MyImage.Visible = False
End If
' You can set any of the other attributes for the ImageButton control here (ALT text, etc)
End Sub
Last edited by shaoen01; 01-05-2006 at 09:55 AM..
|