This is a migrated thread and some comments may be shown as answers.

radgrid image display

7 Answers 221 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dimis vasalos
Top achievements
Rank 1
dimis vasalos asked on 12 May 2011, 01:44 PM
im using radgrid q3 2009.
im loading images via code behind

using the following code

If

 

TypeOf e.Item Is GridDataItem Then

 

 

Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)

 

 

 

If item("mattach").Text = MailHasAttach Then

 

 

Dim img As New System.Web.UI.WebControls.Image

 

 

img.ID =

"attachpic"

 

img.ImageUrl = Session(

"virtualdir") & Session("imagepath") & "attach.gif"

 

item(

"mattach").Controls.Add(img)

 

 

 

'End If

 

 

Else

 

 

Dim img As New System.Web.UI.WebControls.Image

 

 

img.ID =

"attachpic"

 

img.ImageUrl = Session(

"virtualdir") & Session("imagepath") & "blank.gif"

 

item(

"mattach").Controls.Add(img)

 

 

 

End If

 



when binding to datasource the images loaded in grid but when the page is refreshed without rebind it looses the images

could you please help?

7 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 May 2011, 01:54 PM
Hello Dimis,

I suppose that you have added the images in ItemDataBound server-side event. Please note that a better approach to add a dynamically created control to GridItem is to use ItemCreated event handler.

Also you can checkout the following documentation for more information.
Distinguishing the major differences between ItemCreated and ItemDataBound events

Give this suggestion a try and let me know if it helps.

Regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
dimis vasalos
Top achievements
Rank 1
answered on 20 May 2011, 07:14 PM
Dear Sir
your link you have provided me Distinguishing the major differences between ItemCreated and ItemDataBound events

does not work, and anyway i could not implement the same in itemcreated event.

could you please give me another solution?
0
Pavlina
Telerik team
answered on 23 May 2011, 03:41 PM
Hello Dimis,

Please excuse me for the broken link. You can find the correct link here:
http://www.telerik.com/help/aspnet-ajax/grid-distinguish-differences-between-itemcreated-itemdatabound.html

Also, can you please specify why you can not use ItemCreted event?

All the best,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
dimis vasalos
Top achievements
Rank 1
answered on 24 May 2011, 08:48 AM

this is the way im doing it now but when i refresh the page im loosing the images
is there another way i can do that without loosing the images?

Private

 

Sub grd_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles grd.ItemDataBound

 

 

 

If TypeOf e.Item Is GridDataItem Then

 

 

Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)

 

 

 

If item("mattach").Text = MailHasAttach Then

 

 

Dim img As New System.Web.UI.WebControls.Image

 

 

img.ID =

"attachpic"

 

img.ImageUrl = Session(

"virtualdir") & Session("imagepath") & "attach.gif"

 

item(

"mattach").Controls.Add(img)

 

 

 

'End If

 

 

Else

 

 

Dim img As New System.Web.UI.WebControls.Image

 

 

img.ID =

"attachpic"

 

img.ImageUrl = Session(

"virtualdir") & Session("imagepath") & "blank.gif"

 

item(

"mattach").Controls.Add(img)

 

 

 

End If

 

 

If item("mread").Text = MailUnreaded Then

 

 

Dim img As New System.Web.UI.WebControls.Image

 

 

img.ID =

"readpic"

 

img.ImageUrl = Session(

"virtualdir") & Session("imagepath") & "inbox.gif"

 

item(

"mread").Controls.Add(img)

 

 

item.Font.Bold =

True

 

 

'End If

 

 

Else

 

 

Dim img As New System.Web.UI.WebControls.Image

 

 

img.ID =

"readpic"

 

img.ImageUrl = Session(

"virtualdir") & Session("imagepath") & "mail_readed.gif"

 

item(

"mread").Controls.Add(img)

 

 

item.Font.Bold =

False

 

 

End If

 

 

End If

 

 

 

 

 

 

 

 

 

 

End Sub

 




0
Pavlina
Telerik team
answered on 24 May 2011, 10:11 AM
Hello Dimis,

I believe that this issue is caused by the fact that ItemDataBound will be called only during grid data-binding - on post back without explicit data-bind the grid will recreate child controls from ViewState and there will be no ItemDataBound. Please use ItemCreated instead to achieve this.

Kind regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Prashant Khandalkar
Top achievements
Rank 2
answered on 21 Mar 2012, 08:16 AM
 I've stored path of Image in database.
I've used telerik radgrid.
Now I want to display image in telerik radGrid
by the path specified in database.
How is it Possible?
I just did it like we do in asp:GridView but RadGrid displays path as it is instead of image.
<telerik:GridBoundColumn DataField=Coupon_Image FilterControlAltText="Filter Image column"
                        HeaderText="Coupon_Image"
                        UniqueName="Coupon_Image">
                         
                    </telerik:GridBoundColumn>
 
<telerik:GridBoundColumn DataField=Coupon_Image FilterControlAltText="Filter Image column"
                        HeaderText="Coupon_Image"
                        UniqueName="Coupon_Image">
                         
                    </telerik:GridBoundColumn>
Even if I use GridBinaryImageColumn, I will have to store Image in binary format, but I want to fetch the image from database using imagepath only. Please provide me solution on how to display image on RadGrid using imagepath stored in database. I don't want to use memo type of database. I just stored imagepath in database.
0
Pavlina
Telerik team
answered on 23 Mar 2012, 05:48 PM
Hello,

Go through the forum thread below:
http://www.telerik.com/community/forums/aspnet-ajax/grid/show-image-in-radgrid.aspx

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
dimis vasalos
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
dimis vasalos
Top achievements
Rank 1
Prashant Khandalkar
Top achievements
Rank 2
Share this question
or