
Bryan Davis
Top achievements
Rank 1
Bryan Davis
asked on 27 Jan 2010, 06:08 PM
Hello all I posted earlier and got some help, I am still having an issue and was wondering if anybody could tell by looking at my code what I maybe doing wrong. Thanks a bunch. I am trying to add an image to a gridhyperlinkcolumn. I have already looked at this post and this is were I got most of my info/code from but this doesn't work for me. It populates my grid column with a blank, no image. I am a newbie when it comes to this stuff so hopefully somebody can see the error in my way. lol.. Thanks again.
<Columns> |
<telerik:GridHyperLinkColumn NavigateUrl="mywebpage.aspx" |
ItemStyle-Width="20px" HeaderText="Button Column" UniqueName="HyperLinkColumnUniqueName" > |
</telerik:GridHyperLinkColumn> |
Protected Sub rGvTeachers_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) |
If TypeOf e.Item Is GridDataItem Then |
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
Dim hyplnk As HyperLink = DirectCast(item("HyperLinkColumnUniqueName").Controls(0), HyperLink) |
hyplnk.ImageUrl = "~/Email.gif" |
End If |
End Sub |
5 Answers, 1 is accepted
0
Hello Bryan,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Your code seems all right. Attached is also a working sample. Perhaps, the path to the image file is not mapped as expected. Could you right click on the blank images, select properties and see what the path of the image is and whether it is correct.
I hope this helps.
Regards,Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Bryan Davis
Top achievements
Rank 1
answered on 10 Feb 2010, 04:28 PM
Hello, thank you so much for your response. I have not been able to get back on here due to some other issues on hand. I was able to get my images/hyperlinks to work with the sample you provided. I was NOT able to get them to work without using the sqldatasource control that you had in your sample though. This presents problems as I continue with my project. Here is my code I use to populate my grid. This gets the results I am looking for minus the images I need. Is there anything you can see that I need to make the images appear without using the sqldatasource control? Thanks again, Bryan
''' <summary> |
''' Binds the count. |
''' </summary> |
Public Sub BindCount() |
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("default").ToString()) |
Using Command As New SqlCommand("Bryan_Get_CountByID", connection) |
Command.CommandType = CommandType.StoredProcedure |
Command.Parameters.Add(New SqlParameter("@ID", Me.Id)) |
connection.Open() |
Dim reader As SqlDataReader = Command.ExecuteReader() |
RadGrid1.DataSource = reader |
RadGrid1.DataBind() |
reader.Close() |
reader = Nothing |
Command.Dispose() |
connection.Close() |
End Using |
End Using |
End Sub |
''' <summary> |
''' Handles the ItemDataBound event of the RadGrid control. |
''' </summary> |
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) |
If TypeOf e.Item Is GridDataItem Then |
Dim link As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn").Controls(0), HyperLink) |
link.ImageUrl = "~/image1.gif" |
Dim link2 As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn2").Controls(0), HyperLink) |
link2.ImageUrl = "~/image2.gif" |
Dim link3 As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn3").Controls(0), HyperLink) |
link3.ImageUrl = "~/image3.jpg" |
Dim link4 As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn4").Controls(0), HyperLink) |
link4.ImageUrl = "~/image4.gif" |
End If |
End Sub |
0
Hi Bryan,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Without the data-source the grid could not have been bound and generated its items and this is the reason why it is not displaying the images. As for your implementation, could you paste your entire aspx and code behind.
Thanks in advance.
Kind regards,Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Bryan Davis
Top achievements
Rank 1
answered on 16 Feb 2010, 02:42 PM
Hello, here is my code as requested. Thanks again for the help.
<telerik:RadGrid ID="RadGridTest" runat="server" Skin="Forest" GridLines="None"> |
<HeaderContextMenu EnableTheming="True"> |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
</HeaderContextMenu> |
<MasterTableView AutoGenerateColumns="False"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridHyperLinkColumn NavigateUrl="SystemList.aspx" UniqueName="LinkColumn" |
HeaderStyle-Width="20px"> |
</telerik:GridHyperLinkColumn> |
<telerik:GridHyperLinkColumn NavigateUrl="http://www.msn.com" UniqueName="LinkColumn2" |
HeaderStyle-Width="20px"> |
</telerik:GridHyperLinkColumn> |
<telerik:GridHyperLinkColumn NavigateUrl="http://www.google.com" UniqueName="LinkColumn3" |
HeaderStyle-Width="20px"> |
</telerik:GridHyperLinkColumn> |
<telerik:GridHyperLinkColumn NavigateUrl="http://www.yahoo.com" UniqueName="LinkColumn4" |
HeaderStyle-Width="20px"> |
</telerik:GridHyperLinkColumn> |
<telerik:GridBoundColumn DataField="ProgramArea" HeaderText="ProgramArea" SortExpression="ProgramArea" |
UniqueName="ProgramArea"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="TCount" DataType="System.Int32" HeaderText="TCount" |
SortExpression="TCount" UniqueName="TCount"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
<FilterMenu EnableTheming="True"> |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
</FilterMenu> |
</telerik:RadGrid> |
''' <summary> |
''' Handles the Load event of the Page control. |
''' </summary> |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
BindRadGrid() |
AddHandler RadGridTest.ItemDataBound, AddressOf RadGridTest_ItemDataBound |
End Sub |
Public Sub BindRadGrid() |
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("default").ToString()) |
Using Command As New SqlCommand("Get_CountByJobID", connection) |
Command.CommandType = CommandType.StoredProcedure |
Command.Parameters.Add(New SqlParameter("@JobID", Me.JobId)) |
connection.Open() |
Dim reader As SqlDataReader = Command.ExecuteReader() |
RadGridTest.DataSource = reader |
RadGridTest.DataBind() |
reader.Close() |
reader = Nothing |
Command.Dispose() |
connection.Close() |
End Using |
End Using |
End Sub |
''' <summary> |
''' Handles the ItemDataBound event of the RadGridTest control. |
''' </summary> |
Protected Sub RadGridTest_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) |
If TypeOf e.Item Is GridDataItem Then |
Dim link As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn").Controls(0), HyperLink) |
link.ImageUrl = "~/App_Themes/NewTheme/images/image1.gif" |
Dim link2 As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn2").Controls(0), HyperLink) |
link2.ImageUrl = "~/App_Themes/NewTheme/images/image2.gif" |
Dim link3 As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn3").Controls(0), HyperLink) |
link3.ImageUrl = "~/App_Themes/NewTheme/images/image3.jpg" |
Dim link4 As HyperLink = TryCast(DirectCast(e.Item, GridDataItem)("LinkColumn4").Controls(0), HyperLink) |
link4.ImageUrl = "~/App_Themes/NewTheme/images/image4.gif" |
End If |
End Sub |
0
Hello Bryan,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Could you try closing the data-reader at a later stage - in the DataBound event of the grid as explained in the following help article (here) and let me know if it makes a difference.
Regards,Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.