Solved

Gridview - filenames

Posted on 2006-11-18
5
231 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
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:badalpatel
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now