图片时,点击创建一个查询字符串(asp.net/c#) [英] Creating a query string when clicking on image (asp.net/c#)
问题描述
我的应用程序是一个图片库和Repeater控件我正在上市的缩略图(这是在一个单独的文件夹中,除了全尺寸图像)。当缩略图点击满刻度图像应在图像控制fullSizeImage被示出和查询字符串必须设计(与页的一个GET)示出了在满刻度特定图像
有关查询字符串中的code做,但问题是,我没有线索在哪里把它(创建查询)做的,因为超链接控件不支持事件点击。有没有办法使用,例如中继ItemCommand,不然我怎么会完成我想在这里?
办法谢谢!
从Default.aspx的:
< ASP:图片ID =fullSizeImage=服务器/> < ASP:直放站ID =ImageRepeater=服务器的DataSourceID =>
<&ItemTemplate中GT;
< ASP:超链接ID =ImageHyperLinkNavigateUrl ='<%#的eval(姓名,〜/图片/ {0})%GT;' =服务器的CssClass =缩略图>
< ASP:图片ID =Image1的=服务器的ImageUrl ='<%#的eval(姓名,〜/图片/缩略图/ {0})%GT;'的CssClass =缩略图/>
< / ASP:超链接>
< / ItemTemplate中>
< / ASP:直放站>
从code背后:
保护无效的Page_Load(对象发件人,EventArgs的发送){ var目录=新DirectoryInfo的(Gallery.PhysicalApplicationPath +/图片);
变种theFiles = directory.GetFiles(); ImageRepeater.DataSource = theFiles;
ImageRepeater.DataBind(); VAR数据名=的Request.QueryString [名称];
fullSizeImage.ImageUrl =数据名称;
}
在创建查询字符串(我不知道往哪里放):
字符串str =的ImageUrl; < - 点击的图像的URL
的Response.Redirect(?Default.aspx的名字=+ Server.UrlEn code(STR);
这适用于我。
< ASP:;?〜/ Default.aspx的名字=超链接ID =ImageHyperLinkNavigateUrl ='&LT%#+ Server.UrlEn code(EVAL( 姓名,〜/图片/ {0}))%GT;' =服务器的CssClass =缩略图>
< ASP:图片ID =Image1的=服务器的ImageUrl ='<%#的eval(姓名,〜/图片/缩略图/ {0})%GT;'的CssClass =缩略图/>
< / ASP:超链接>
My application is an image gallery and with a Repeater control i'm listing the thumbnails (that's in a separate folder, apart from the full scale images). When clicking on a thumbnail a full scale image should be shown in the Image control "fullSizeImage" and a query string should be created which (with a GET of the page) shows that specific image in full scale.
The code for the query string is done, but the problem is that I don't have a clue where to put it (the creation of the query), because the HyperLink control doesn't support event clicks. Is there a way to use for example Repeater ItemCommand, or how could I accomplish what I want here?
Thanks!
from default.aspx:
<asp:Image ID="fullSizeImage" runat="server" />
<asp:Repeater ID="ImageRepeater" runat="server" DataSourceID="" >
<ItemTemplate>
<asp:HyperLink ID="ImageHyperLink" NavigateUrl='<%# Eval("Name", "~/Images/{0}") %>' runat="server" CssClass="thumbnails" >
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Name", "~/Images/Thumbnails/{0}") %>' CssClass="thumbnail" />
</asp:HyperLink>
</ItemTemplate>
</asp:Repeater>
from code behind:
protected void Page_Load(object sender, EventArgs e) {
var directory = new DirectoryInfo(Gallery.PhysicalApplicationPath + "/Images");
var theFiles = directory.GetFiles();
ImageRepeater.DataSource = theFiles;
ImageRepeater.DataBind();
var dataName = Request.QueryString["name"];
fullSizeImage.ImageUrl = dataName;
}
the creation of the query string (that I don't know where to put):
string str = ImageUrl; <- the url of the clicked image
Response.Redirect("default.aspx?name=" + Server.UrlEncode(str);
This works with me
<asp:HyperLink ID="ImageHyperLink" NavigateUrl='<%# "~/default.aspx?name=" + Server.UrlEncode(Eval("Name","~/Images/{0}")) %>' runat="server" CssClass="thumbnails" >
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Name", "~/Images/Thumbnails/{0}") %>' CssClass="thumbnail" />
</asp:HyperLink>
这篇关于图片时,点击创建一个查询字符串(asp.net/c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!