Hope all is well with everyone today.
I have run into a little problem that I am struggling with, I'm sure it's probably something simple but the longer I stare at it the less sense it seems to make.
I have a details view, which has in it a listview. The listview displays images. I have wrapped around the images an asp:hyperlink but an unable to set the navigateUrl from the code behind, which I am trying to do from the listviews databound event. For some reason the hyperlink control is proving difficult to find.
my .aspx:
<asp:DetailsView ID="productDetails" OnDataBound="productDetails_DataBound" runat="server" AutoGenerateRows="false">
<Fields>
<asp:TemplateField>
<ItemTemplate>
<div class="row">
<div class="col-sm-12">
<h2 id="prodNamelbl" runat="server" class="text-center"><%# Eval("ProductName") %></h2>
<asp:Image ID="prodMainImage" runat="server" ImageAlign="Middle" ImageUrl='<%# Eval("ImagePath") %>' />
</div>
</div>
<div class="row">
<div class="col-sm-12">
<asp:ListView ID="listOtherImages" OnDataBound="listOtherImages_DataBound" OnPagePropertiesChanging="listOtherImages_PagePropertiesChanging" runat="server">
<LayoutTemplate>
<div class="row">
<div runat="server" id="itemPlaceholder"></div>
</div>
<asp:DataPager runat="server" PagedControlID="listOtherImages" ID="imgListDataPager"
PageSize="3">
<Fields>
<asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="true"
ShowNextPageButton="false" />
<asp:NumericPagerField ButtonType="Link" />
<asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton = "false" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<div class="col-sm-4">
<asp:HyperLink ID="imgLink" runat="server" >
<asp:Image ID="supImage" Height="80px" Width="80px" ImageAlign="AbsMiddle" AlternateText='<%# Eval("ImgId") %>' ImageUrl='<%# Eval("ImagePath") %>' runat="server" />
</asp:HyperLink>
</div>
</ItemTemplate>
</asp:ListView>
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
my code behind:
protected void listOtherImages_DataBound(object sender, EventArgs e)
{
ListView imgs = (ListView)productDetails.FindControl("listOtherImages");
foreach (ListViewItem item in imgs.Items)
{
try
{
// find controls
Image prodImage = (Image)item.FindControl("supImg");
HyperLink picLink = (HyperLink)item.FindControl("imgLink");
// assign value to NavigateUrl
picLink.NavigateUrl = "~/ProductCatalogue/prodImage.aspx?ImageId=" + prodImage.AlternateText;
}
catch (Exception err)
{
lblError.Text = "Error finding controls: " + err.Data + "<br />" + err.Message + "<br />" + err.InnerException;
}
}
}
Thank you in advanced to anyone who can help ;)