thks for the response of both of you.
on button click I am writing code to execute stored procedure to fetch the data from database and it is fetching and filling the gridview correctly. Now I want to add a photo on the top row of each column in gridview. The stored procedure is also fetching the name of image file from the databse.
I am writing following code to get the image displayed, but this is not happening.
-
Protected Sub grdResult_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdResult.RowDataBound
-
If e.Row.RowType = DataControlRowType.DataRow Then
-
If e.Row.RowIndex = 0 Then
-
Dim drv As DataRowView = e.Row.DataItem
-
For intCellCnt = 1 To e.Row.Cells.Count - 1
-
Dim img As New Image
-
-
img.Width = Unit.Pixel(80)
-
img.Height = Unit.Pixel(80)
-
-
If intCellCnt = 1 Then img.BorderColor = Drawing.Color.Red
-
img.ImageUrl = "~/imgs/" & drv.Item(2).ToString
-
e.Row.Cells(intCellCnt).Text = ""
-
e.Row.Cells(intCellCnt).Controls.Add(img)
-
Next
-
End If
-
when I see the properties of the image which is not being displayed, I found it is going till folder imgs, that's it.drv.item(2) is null. I think that's why image is not being displayed.
Please suggest some solution.
Thanks
Are simply trying to display images in the Row Header?
If so, your line
-
If e.Row.RowType = DataControlRowType.DataRow
Should check for DataControlRowType.Header instead of DataControlRowType.DataRow....only when you are on the Header should you be adding images.
Also, where are your images located?
They have to be some place that is accessible to the web page...in other words they have to be on your web server (in the wwwroot folder)...according to you they are in your application's root in a folder named "imgs". Are they there?
If this is the case why are you even storing the names of the files in the database? Why not just use the images as such?
In the future could you please post your code in [code] tags (See
How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
-Moderator Frinny