Solved

ASP.net VB.net Adding images to a progrematically added GridView

Posted on 2016-09-21
5
38 Views
Last Modified: 2016-09-21
Hi
I am using the following code to add a GridView to my ASP.net webform panel. I am trying to create a column that shows images
from my resources. If I add a GridView manually I use the DataImageUrlField property to specify where the image is, but I don't know how to do this programatically

                       Dim oGridView As New GridView
                        oGridView.ID = "Control" & CStr(oCount)
                        oGridView.Style("Width") = "100%"
                        'NOTE: PREVENT ENTER BUTTON TRIGGERING btnSave_Click EVENT
                        oGridView.Attributes.Add("onkeydown", "return (event.keyCode!=13);")

                        Dim bfield As New BoundField()
                        bfield.HeaderText = "Name"
                        bfield.DataField = "Name"
                        oGridView.Columns.Add(bfield)

Open in new window

0
Comment
Question by:Murray Brown
[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
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41808212
If I add a GridView manually I use the DataImageUrlField property to specify where the image is, but I don't know how to do this programatically

you can do it in RowDataBound event ?
0
 

Author Comment

by:Murray Brown
ID: 41808216
Hi. Thanks. Would you be able to show me an example of that code
0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41808262
something like this?

Dim bImageField As New ImageField()
        bImageField.DataImageUrlField = "<image url>"

Open in new window


I guess you want to load static image into your gridview?
0
 

Author Comment

by:Murray Brown
ID: 41808417
Hi. Here is my code. At the bottom I show the results in the GridView. cloud1.jpg is an image in my resources

Sub Test
                        Dim oGridView As New GridView
                        oGridView.ID = "Control" & CStr(oCount)
                        oGridView.Style("Width") = "100%"
                        oGridView.Attributes.Add("onkeydown", "return (event.keyCode!=13);")

                        Dim bImageField As New ImageField()
                        bImageField.DataImageUrlField = "Text1"
                        oGridView.Columns.Add(bImageField)

                        oLoadGrid(oGridView, "Select * From Test2")

                        Me.Panel_Controls.Controls.Add(oGridView)
End Sub

    Sub oLoadGrid(ByVal oGridView As GridView, ByVal oSQL As String)

        Dim cs As String = ConfigurationManager.ConnectionStrings("PSQL").ConnectionString
        Dim cn As New SqlConnection(cs)

        Try

            Dim cmd As New SqlCommand(oSQL, cn)

            '// open the connection
            cn.Open()

            '// execute the sql statement
            Using reader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

                oGridView.DataSource = reader
                oGridView.DataBind()

            End Using

        Catch ex As Exception
            Response.Write(ex.Message & " yuma310")
        Finally
            If cn.State <> ConnectionState.Closed Then
                cn.Close()
            End If
        End Try
    End Sub

1
0
 

Author Closing Comment

by:Murray Brown
ID: 41808420
OK it actually worked. Thanks very much for your help. Greatly appreciated!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

626 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