3

Currently in my webpage i load images to the ListView object as follows...

 <ContentTemplate>
            <asp:ListView ID="ListView1" runat="server">
                <layouttemplate>
                    <asp:PlaceHolder id="itemPlaceholder" runat="server" />
                </layouttemplate>
                <ItemTemplate>
                        <td>
                            <asp:Image ID="Image1" runat="server"  
                    ImageUrl = '<%# DataBinder.Eval(Container.DataItem, "Image") %>' />
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>
 </ContentTemplate>

Now, i would like to use a combination of a Generic Handler and the ListView object to serve the images into the ListView

...the generic handler call is like

~/Handlers/Image.ashx?img=

How could i combine both above to serve images?

I tried something like the following but it is not correct

<asp:Image ID="Image1" runat="server"  
                        ImageUrl = ~/Handlers/Image.ashx?img= & '<%# DataBinder.Eval(Container.DataItem, "Image") %>' />

So what is the correct way?

OrElse
  • 9,709
  • 39
  • 140
  • 253

2 Answers2

1

Yes that is the correct way. Your syntax for binding the ImageUrl not correct though. Try this one:

<asp:Image ID="Image1" runat="server" ImageUrl ='<%# "~/Handlers/Image.ashx?img=" + Eval("Image")%>' />

You might also use the ItemDataBound event to use code like this:

Image image1 = e.FindControl("Image1") as Image;
YourClass item = e.DataItem as YourClass;
image1.ImageUrl = String.Format("~/Handlers/Image.ashx?img={0}", item.Image")
citronas
  • 19,035
  • 27
  • 96
  • 164
0

Try this

<ItemTemplate>
<asp:Hyperlink runat= "server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName").ToString()%>'                               NavigateUrl='<%# "page.aspx?Name=" & DataBinder.Eval (Container.DataItem,"ProductName").tostring %>' ID="ProductName"/>   
</ItemTemplate>

Hope it helps

Source : http://www.extremeexperts.com/Net/FAQ/PassingMulitpleParameterinURLLink.aspx

citronas
  • 19,035
  • 27
  • 96
  • 164
Anuraj
  • 18,859
  • 7
  • 53
  • 79