This topic is locked

Select image to be displayed through combo box

1/11/2007 3:24:32 AM
ASPRunnerPro General questions
orit author

I have a table that displays upload documents. I want that beside each uploaded document will be an image that represents its file type (icon for word, icon for excel, icon for power-point etc...). I think of 2 options:

  1. that the application will recognize the file type according the file's extension and will display the appropriate image
  2. In the _add page will be a como box with list of file types, each item in the list reprents the relevant image and after the user select the type in the list in the _add page, the appropriate image will be displayed in the _list page.

I'm assuming that the 2nd one is easier. How to do that?
Thanks

Sergey Kornilov admin 1/11/2007

I would choose the first option.
You can use Custom field to get file extension and use simple logic to display an appropriate image.
Sample code:
strExt = LCase(Left(strValue,3))

if strExt="doc" then

strValue="<img src='images/word.gif'>"

else if strExt="xls" then

strValue="<img src='images/excel.gif'>"

else if strExt="ppt" then

strValue="<img src='images/powerpoint.gif'>"

end if
orit author 1/15/2007

Thanks.

2 Questions.

  1. As far as I understand from the code, the value of the field suppose to be the file name. correct? if yes, How can I enter into this field the value of the uploaded file? If not, how to define this field?
  2. When I try to get into the application, I get the message "The page can't be displayed" with the information:

    Error Type:

    Microsoft VBScript compilation (0x800A03F4)

    Expected 'If'

    /PM/Applications/pm_approval/include/commonfunctions.asp, line 328, column 4
    Browser Type:

    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
    Page:

    GET /PM/Applications/pm_approval/login.asp
    lines 308 to 328 contain the following code:

' return custom expression

Function CustomExpression(data, field, table)

If table = "" Then table = strTableName

strValue = data(field)

If table = "release_approval" And field = "fileType" Then

strExt = LCase(Left(strValue,3))

if strExt="doc" then

strValue="<img src='images/bardoc.gif'>"

else if strExt="xls" then

strValue="<img src='images/barxls.gif'>"

else if strExt="ppt" then

strValue="<img src='images/barppt.gif'>"

else if strExt="txt" then

strValue="<img src='images/bartxt.gif'>"

else if strExt="pdf" then

strValue="<img src='images/barpdf.gif'>"

end if
End If

CustomExpression = strValue

End Function



(End Function on line 328)

What is the problem?
Thanks a lot

J
Jane 1/15/2007

Orit,
yes, the value of the field is file name. Set up this field as File on the "Edit as" settings dialog on the Visual Editor tab and select your file on the ADD or EDIT page.

Here is correct code:

strExt = LCase(Left(strValue,3))

if strExt="doc" then

strValue="<img src='images/word.gif'>"

elseif strExt="xls" then

strValue="<img src='images/excel.gif'>"

elseif strExt="ppt" then

strValue="<img src='images/powerpoint.gif'>"

end if

orit author 1/15/2007

Thanks,

I store the file name in a different field and displays this field to download the file.

Is there a way I can refernce to the other field in the code instead of checking the last 3 digits of the current field?

If yes, how to do that?

If not, Is there a way that I can make the value of this field equal to the value of my field where I upload the file?
Thanks a lot

Sergey Kornilov admin 1/15/2007

You can reference any field on the list page using rs("FieldName")

orit author 1/16/2007

Thanks a lot,
My code is now:

' return custom expression

Function CustomExpression(data, field, table)

If table = "" Then table = strTableName

strValue = data(field)

If table = "release_approval" And field = "fileType" Then

strExt = LCase(Left(rs("fileName"),3))

if strExt="doc" then

strValue="<img src='images/bardoc.gif'>"

elseif strExt="xls" then

strValue="<img src='images/barxls.gif'>"

elseif strExt="ppt" then

strValue="<img src='images/barppt.gif'>"

else

strValue="<img src='images/barna.gif'>"

end if

End If

CustomExpression = strValue

End Function


("fileName" is the name of the field that holds the name of the uploaded file)
For some reason, the "fileType" field stays empty for all records.

What can be the reason?
Thanks

Sergey Kornilov admin 1/16/2007

How the value of fileType field is relevant in context of this code?

orit author 1/16/2007

The only function of the fileType field is that the appropriate image suppose to sit on this column.

What is incorrect?
Thanks

orit author 1/17/2007

The fileType field is actually only a placeholder for the type image and is not part of the add\edit pages. Following your answer that fields that are updated through lookup wizard or radio buttons can't hold custom code in list view, Is there any problem to have custom code for this fileType field which actually doesn't hold data\value?

If yes, Is there a way to add this image in a column without assigning a field in the database to it? If yes - How?

If not - any idea why the code doesn't affect my application?
Thanks