如何在转发器内的hyperLink navigateUrl中传递参数(How to pass argument in hyperLink navigateUrl inside a repeater)

我正在开发一个视频门户应用程序,我使用了一个html模板进行设计。 我用asp:Repeater控件显示所有视频图像。 单击特定图像时,页面将重定向到视频详细信息页面。 这是我的HTML代码,

<asp:Repeater ID="rp_videos" runat="server"> <ItemTemplate> <div class="col-md-4 col-sm-6 small-grid"> <div class="vid-img-holder wow pulse" data-wow-duration="1s"> <div class="top-shadow"> <span>'<%# Eval("time_before") %>'</span> <span>From <a href="https://www.youtube.com/"><i class="fa fa-youtube-play"></i></a></span> <span><i class="fa fa-eye"></i>'<%# Eval("views") %>'</span> </div> <asp:HyperLink ID="hl_video_img" runat="server" NavigateUrl="~/Views/VideoDetail.aspx"> <asp:HiddenField ID="hf_file" runat="server" Value="'<%# Eval("file") %>'" /> <asp:Image ID="img_video_image" runat="server" class="img-responsive hidden-sm hidden-xs" ImageUrl='<%# Eval("image") %>' AlternateText="video_thumb" /> <img class="img-responsive hidden-md hidden-lg" src="../images/main-vid-image-smmd-1.jpg" alt="video_thumb" /> <span class="play-icon"> <img class="img-responsive play-svg svg" src="../images/play-button.svg" alt="play" onerror="this.src='images/play-button.png'" /> </span> </asp:HyperLink> <h3 class="vid-author"> <span>By <a href="~/Views/Profile.aspx" title="Posts by admin" rel="author">'<%# Eval("publisher_name") %>'</a> </span> <a href="video-detail.html">'<%# Eval("title") %>'</a> </h3> <div class="bottom-shadow"></div> <div class="overlay-div"></div> </div> </div> </ItemTemplate> </asp:Repeater>

我想传递一个被点击的视频的细节,这里是所有视频页面的视图。

I am working on a video portal application, I have use a html template for designing. I have use asp:Repeater control display all the video images. When a specific image is clicked the page is redirected to video detail page. Here is my html code,

<asp:Repeater ID="rp_videos" runat="server"> <ItemTemplate> <div class="col-md-4 col-sm-6 small-grid"> <div class="vid-img-holder wow pulse" data-wow-duration="1s"> <div class="top-shadow"> <span>'<%# Eval("time_before") %>'</span> <span>From <a href="https://www.youtube.com/"><i class="fa fa-youtube-play"></i></a></span> <span><i class="fa fa-eye"></i>'<%# Eval("views") %>'</span> </div> <asp:HyperLink ID="hl_video_img" runat="server" NavigateUrl="~/Views/VideoDetail.aspx"> <asp:HiddenField ID="hf_file" runat="server" Value="'<%# Eval("file") %>'" /> <asp:Image ID="img_video_image" runat="server" class="img-responsive hidden-sm hidden-xs" ImageUrl='<%# Eval("image") %>' AlternateText="video_thumb" /> <img class="img-responsive hidden-md hidden-lg" src="../images/main-vid-image-smmd-1.jpg" alt="video_thumb" /> <span class="play-icon"> <img class="img-responsive play-svg svg" src="../images/play-button.svg" alt="play" onerror="this.src='images/play-button.png'" /> </span> </asp:HyperLink> <h3 class="vid-author"> <span>By <a href="~/Views/Profile.aspx" title="Posts by admin" rel="author">'<%# Eval("publisher_name") %>'</a> </span> <a href="video-detail.html">'<%# Eval("title") %>'</a> </h3> <div class="bottom-shadow"></div> <div class="overlay-div"></div> </div> </div> </ItemTemplate> </asp:Repeater>

I want to pass the detail of a video which is clicked, here is the view of all video page.

最满意答案

在您的超链接中添加导航URL中的代码( 您必须使用单引号

<asp:HyperLink ID="hl_video_img" runat="server" NavigateUrl='~/Views/VideoDetail.aspx?videoid=<%# DataBinder.Eval(Container.DataItem,"video_id")%>'>

因此,您生成正确的链接,并传递要打开的视频的ID。

现在在VideoDetail.aspx中添加代码以从page_load函数中的Query String获取参数

if (Request.QueryString.HasKeys()) { try { //get the id from query string string videoID = Request.QueryString["videoID"].ToString(); } catch { } }

In your hyperlink add the code in the Navigate URL (you have to use single quotes)

<asp:HyperLink ID="hl_video_img" runat="server" NavigateUrl='~/Views/VideoDetail.aspx?videoid=<%# DataBinder.Eval(Container.DataItem,"video_id")%>'>

So you generate the proper link and you pass the id of the video you want to open.

Now in your VideoDetail.aspx add the code to get the parameter from the Query String in your page_load function

if (Request.QueryString.HasKeys()) { try { //get the id from query string string videoID = Request.QueryString["videoID"].ToString(); } catch { } }

更多推荐