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
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.
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?
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.
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
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.
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>
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