Changing ListView Column Contents at Run-Time

2 posts, 0 answers
  1. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 20 Oct 2010 Link to this post

    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!


  2. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 22 Oct 2010 Link to this post

    I found the solution to this problem on the 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"
            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!

  3. Telerik UI for ASP.NET Core is out
Back to Top