?
Solved

Gridview - filenames

Posted on 2006-11-18
5
Medium Priority
?
268 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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