Hi everyone,
in my project I try display in GridView rows clickable images (HyperlinkField). Datasource is Access2000 database with fields ID (Autonumber), Name (string – is the same as name of appropriate image in Images folder; type of all images is .jpg). Objective is – when user click clickable image application open another page with detail information of selected row.I tried make this according to http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/demos/HyperLinkFieldImageUrl.aspx example and I assume error is in script code.
Every help will be much appreciated.
Larry5
My code is :<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<script runat="server">
public void getImages(Object src, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
DataRowView rowView = (DataRowView)e.Row.DataItem;
string ID = rowView["ID"].ToString();
TableCellCollection myCells = e.Row.Cells;
HyperLink planLink = (HyperLink)myCells[myCells.Count - 1].Controls[0];
planLink.ImageUrl = string.Format("~/Images/{0}.jpg", ID);
planLink.ToolTip = rowView["ID"].ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="GridVsource" Width="294px">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:HyperLinkField DataNavigateUrlFields="ID"
DataNavigateUrlFormatString="DetailsV_page.aspx?id={0}" HeaderText="clickableImage" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="GridVsource" runat="server"
DataFile="~/App_Data/data.mdb"
SelectCommand="SELECT [ID], [Name], [Price] FROM [Books]">
</asp:AccessDataSource>
</div>
</form>
</body>
</html>