Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Gridview - filenames

I have this code under Page load. How can I add filenames and create a hyperlink in table ?

  Const IMAGE_DIRECTORY As String = "myimages/"
        Dim s, html As String

        Dim sb As New StringBuilder()
   
        For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")

            html = "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">"
            sb.Append("&nbsp;&nbsp;" & html)

        Next

        litImages.Text = sb.ToString
 
End Sub
Avatar of badalpatel
badalpatel

u can use the htmlgeneric control..

Const IMAGE_DIRECTORY As String = "images/"
        Dim s As String
        Dim html As New HtmlGenericControl
        Dim sb As New StringBuilder()

        For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")

            html.InnerHtml &= "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">"     'here u can use any html u want to place....


        Next
        place.Controls.Add(html)

and in design page u have to give <td> a id so u can place content of htmlgenericcontrol to this <td>
   <table>
            <tr>
                <td id ="place" runat="server">
                </td>
            </tr>
        </table>
Here you go:

        Const IMAGE_DIRECTORY As String = "myimages/"
        Dim s, html As String

        Dim sb As New StringBuilder
        html = "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1>"
        For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")
            html = html & "<TR>"
            html = html & "<TD><img src="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "" width=520 height=400></TD>"
            html = html & "<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD>"
            html = html & "</TR>"
        Next
        html = html & "</TABLE>"
        litImages.Text = sb.ToString

>>> Here you can use this html string to display in any other control.
Avatar of VBdotnet2005

ASKER

It does not display any images

Const IMAGE_DIRECTORY As String = "myimages/"
        Dim s, html As String

        Dim sb As New StringBuilder
        html = "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1>"
        For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")
            html = html & "<TR>"
            html = html & "<TD><img src="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "" width=520 height=400></TD>"
            html = html & "<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD>"
            html = html & "</TR>"
        Next
        html = html & "</TABLE>"
        litImages.Text = sb.ToString

    End Sub
Code below display images almost the same as mine. That does not answer my question at all.

Const IMAGE_DIRECTORY As String = "images/"
        Dim s As String
        Dim html As New HtmlGenericControl
        Dim sb As New StringBuilder()

        For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")

            html.InnerHtml &= "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">"     'here u can use any html u want to place....


        Next
        place.Controls.Add(html)

and in design page u have to give <td> a id so u can place content of htmlgenericcontrol to this <td>
   <table>
            <tr>
                <td id ="place" runat="server">
                </td>
            </tr>
        </table>
ASKER CERTIFIED SOLUTION
Avatar of badalpatel
badalpatel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial