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

How to change HREF column image source at run time.

1 Answer 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 30 Nov 2010, 11:19 PM
Folks,

I am using RAD Control from ASP.Net Ajax Q3 2010 with Vstudio 2008 SP1.

In my project, I am using similar to Window / Using the URL for Server Arguments.

I would like to see depending on the value of Country, the HREF image should show approprite Image file. For example after Grid Databound,  if the the Databound column Country value  = "France" then for that row my Href column image src be = "Images/FranceData.png". if the Databound column Country value  = "Germany" then for that row  my Href column image src be ="Images/GermanyData.png".

Ofcourse in my Images folder both FranceData.png and GermanyData.png  exists. Below is my Gridview declarations.

Thanks

GC_0620

<asp:GridView ID="GridView1" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
CellPadding="0" GridLines="None" CellSpacing="0" runat="server" CssClass="RadGridLike">
<HeaderStyle CssClass="GridHeader"></HeaderStyle>
<Columns>
<asp:BoundField DataField="CompanyName" HeaderText="Company Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
  
<asp:TemplateField HeaderText="Details">
<ItemTemplate>
  
<a href="#" onclick="openRadWindow('<%#DataBinder.Eval(Container.DataItem,"CustomerID")%>'); return false;">
<img style="border:0px;vertical-align:middle;" alt="" src="Images/FranceData.png" /></a
  
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 10 [CompanyName], [CustomerID], [ContactName], [Country] FROM [Customers]">
</asp:SqlDataSource>

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 06 Dec 2010, 03:42 PM
Hi,

You can construct the src attribute of the image by binding it to the data from the Country field. Here is a code snippet (assuming all the images names end with Data.png):
<img style="border:0px;vertical-align:middle;" alt="" src="Images/<%#DataBinder.Eval(Container.DataItem,"Country")%>Data.png" /></a>

Let me know how this works for you and if have any other questions.

Regards,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart 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.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or