c# - Get Image url from method -
i have image , want image url method .i found questions on web.but answer not quite. source follows:
<img id="largeimage" src='<%#showlast() %>' alt="" />
cs file follows:
public string showlast() { using (dbmldatacontext dc=new dbmldatacontext()) { var query = (from d in dc.news select d).last(); return query.photo.tostring(); } }
whats happening? if using inside databound control <%#
right. if not want use <%=
or better yet 1 of variations encode output.
based on comments sounds should use <asp:image>
control , set imageurl
property in codebehind.
markup:
<asp:image runat="server" id="largeimage" generateemptyalternatetext="true" />
code behind:
// in page load largeimage.imageurl = showlast();
the gotcha can think of approach if using id "largeimage" in css or somesuch. converting asp.net control means take control of id need target through css cssclass
property or if using modern version of .net have other options set id static id - i'll update again if issue.
Comments
Post a Comment