Use of superlinks in asp.net GridView (with parameters)

Source: Internet
Author: User

Method 1. Use the <a> label,
Front-end:
Copy codeThe Code is 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 ") %>") '> displayed </a>

Use the <a> label and do not refresh the Home Page
Method 2. asp: HyperLink
(1) Foreground: <asp: HyperLink ID = "hyperLink" runat = "server" Text = '<% # Eval ("OperationFlag ") %> 'target = "_ blank"> </asp: HyperLink>
Backend binding path:
Copy codeThe Code is 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"); // obtain the parameter to be passed through the hidden field
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>
When asp: HyperLink is used, the page does not refresh the homepage.
Method 3.asp: LinkButton
(1) Foreground: <asp: LinkButton ID = "tb_searchori" runat = "server" Text = "pop-up" OnClientClick = <% # "window. open ('origimageshow. aspx? Image_id = "+ Eval (" id ") +" ') "%> </asp: LinkButton>
(2) Foreground: <asp: linkButton ID = "tb_searchori" runat = "server" Text = "pop-up" OnClick = "LB_Ori_Click" CommandArgument = '<% # Bind ("ID ") %> '> </asp: LinkButton>
Copy codeThe Code is 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 homepage after the page is displayed.
To sum up, we recommend Using HyperLink or.

Related Article

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.