Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Gridview - filenames

Posted on 2006-11-18
5
Medium Priority
?
270 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:badalpatel
ID: 17977344
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>
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17977521
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.
0
 

Author Comment

by:VBdotnet2005
ID: 18001085
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
0
 

Author Comment

by:VBdotnet2005
ID: 18001095
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>
0
 
LVL 6

Accepted Solution

by:
badalpatel earned 2000 total points
ID: 18001117
try this code
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 &= "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1><TR>"
            html.InnerHtml &= "<TD><img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400""></TD>"     'here u can use any html u want to place....
           html.InnerHtml &="<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD></tr></table>"

        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>
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question