Use of hyperlinks in the ASP.net gridview (with parameters) _ Practical Tips

Source: Internet
Author: User
Method 1. Using <a> label,
Front desk:
Copy Code code as follows:

<a href= ' <%# ' origimageshow.aspx?id=1&image_id= +eval ("id")%> ' id= ' tb_search ' runat= ' server ' target= ' _ Blank "> Pop-up </a>
<a href= ' Javascript:alert ("<%# origimageshow.aspx?image_id=" + Eval ("id")%> ") ' > Popup </a>

Use <a> tab, do not refresh main Page
Method 2.:asp:hyperlink
(1) Front desk: <asp:hyperlink id= "HyperLink" runat= "server" text= ' <%# Eval ("Operationflag")%> ' target= ' _blank ' > </asp:HyperLink>
Background binding path:
Copy Code code as follows:

protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
if (E.row.rowtype = = Datacontrolrowtype.datarow)
{
HyperLink Btnlink = (HyperLink) e.row.cells[3]. FindControl ("HyperLink");
HiddenField Hidderid = (HiddenField) e.row.cells[3]. FindControl ("log_id");//Get parameters to pass through hidden fields
String url = string. Empty;
if (Hidderid!= null)
{
url = "~/imagemanage/logpicdetails.aspx?id=" + Hidderid. Value;
Btnlink. NavigateUrl = URL;
}
}
}

(2) <asp:hyperlink id= "HyperLink1" runat= "server" Navigateurl= ' <%# ' origimageshow.aspx?image_id= ' + Eval ("ID")% > '
text= "pop-up" target= "_blank" ></asp:HyperLink>
Using Asp:hyperlink, the pop-up page does not refresh the main page
Method 3.asp:linkbutton
(1) Front desk: <asp:linkbutton id= "Tb_searchori" runat= "Server" text= "pop-up" onclientclick=<%# "window.open" (' Origimageshow.aspx?image_id= "+eval" ("id") + "')"%> ></asp:LinkButton>
(2) Front desk: <asp:linkbutton id= "Tb_searchori" runat= "Server" text= "pop-up" onclick= "Lb_ori_click" commandargument= "<%#" Bind ("ID")%> ' ></asp:LinkButton>
Copy Code code as follows:

protected void Lb_ori_click (object sender, EventArgs e)
{
LinkButton lbtn = (LinkButton) sender;
int imgid = Int. Parse (Lbtn.CommandArgument.ToString ());
String url = "origimageshow.aspx?image_id=" + imgid;
url = page.resolveurl (URL);
Page.ClientScript.RegisterStartupScript (Page.gettype (), "Messid", "<script language= ' JavaScript ' > window.open (' "+ URL +" ');</script> ");
}

Use Asp:linkbutton to refresh the home page after a pop-up
To sum up: recommend the use of hyperlink or a way

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.