简体   繁体   中英

Hyperlink in an ASP Gridview with a CommandName

Does anyone know how to add a commandName to an asp hyperlink in a gridview. Or is there any other way of doing this. I know you can use a linkbutton but i need the user to be navigated to a new tab. The hyperlink can do this with the target attribute.

Any help is greatly appreciated

Unfortunately you can't have the best of both worlds built right in here (postback handing, allowing for CommandName and Target ); you will need to A) use a link and disregard commands, or B) use a LinkButton to handle the command in the postback then redirect manually.

In the latter case B, you could perhaps register a script to execute the redirection and maintain specifying the target in that manner. For example:

ScriptManager.RegisterStartupScript(
    page,
    typeof(Page),
    "Redirect",
    "window.open(" + "\"" + url + "\"" + ", \"_blank\");",
    true);

在“超链接”的“属性”中,可能是这样的:

<asp:HyperLink ID="Lk1" runat="server" Target="_Blank" NavigateUrl='<%# Bind("someid","detail?id={0}") %>'><asp:Label ID="Label1" Runat="Server" /></asp:HyperLink>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM