Serving an image with a generic handler within a list view. Is it possible?
Currently in my webpage i load images to the ListView object as follo开发者_开发技巧ws...
<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?
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")
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
精彩评论