This is a migrated thread and some comments may be shown as answers.

Changing ListView Column Contents at Run-Time

1 Answer 76 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 20 Oct 2010, 06:49 PM
I have looked through the threads for something similar and have not found anything to help me...

I have a listview that contains rows populated manually at runtime from a datatable created in the NeedDataSource event.  The columns in the datatable are bound to certain specific items in the listview.  In general, this is all working fine.

However, one of the columns in the datatable contains a path/file name to an image related to the data record.  This path/file name may contain a valid path or it may be an empty string ("").

If the path/file name contains data (a path/file name), then I want to display that image (photo) in a column in the the related row in the listview.

If the path/file name contains an empty string, then I want to display a "no image available" type of graphic.

This is the first time I have attempted to use the Listview control, so I'm not certain how/when to programmatically access/manipulate it to accomplish this goal.

Do you have a sample or some sample code that does this?

Thanks in advance!

Lynn


1 Answer, 1 is accepted

Sort by
0
Lynn
Top achievements
Rank 2
answered on 22 Oct 2010, 06:14 PM
I found the solution to this problem on the asp.net forum and this item may be closed.

The solution I discovered was to call a function from inside the Eval statement like...

<asp:Image ID="Image1" runat="server" BorderStyle="Inset" BorderWidth="2px" AlternateText="Category Photo" ToolTip="Category Photo" Width="132px" Height="90px" ImageUrl='<%# EvaluatePhotoPath(Eval("MediaPath"), Eval("Listing"), Eval("MediaFileName"))%>' />


In the code behind page, I included the following VB function...

Public Function EvaluatePhotoPath(ByVal MediaPath As String, ByVal Listing As Integer, ByVal MediaFileName As String) As String
    If MediaFileName = "" Then
        Return MediaPath & "/" & "NoImage.bmp"
    Else
        Return MediaPath & "/" & Listing & "/" & MediaFileName
    End If
End Function

This works great and I see no delay in response time when it executes.

Sorry to have bothered you!

Lynn
Tags
ListView
Asked by
Lynn
Top achievements
Rank 2
Answers by
Lynn
Top achievements
Rank 2
Share this question
or