|
Creating a HyperLink in a DataGrid that Opens in a New Window
By:
Scott Mitchell
|
Created: 2003-05-11
|
Last Updated: 2003-05-15
|
Printer-Friendly Version
As discussed in Chapter 4 of ASP.NET Data Web Controls Kick Start, the DataGrid Web control can have a number of different
column types. The most common column type is the BoundColumn, which simply displays the value of a particular The hyperlink generated by the HyperLinkColumn, when clicked, loads the specified URL in the same window as the DataGrid. However, many developers have asked on newsgroups and the ASP.NET DataGrid/DataList/Repeater forum how to have the hyperlink cause the specified URL to open in a different window. There are two ways to accomplish this:
The first technique is much simpler to implement. However, the second technique allows for more control over the window that is created for the link to be displayed in. That is, with the client-side JavaScript approach, you can specify the precise height and width of the window, whether or not is will have a location bar, a status bar, if it's resizable, and other settings.
Using the Target PropertyThe simplest way to get a DataGrid's HyperLinkColumn hyperlink to load in another window is to set the HyperLinkColumn's Target property to _blank. The following code (and associated
live demo), show the use of this property:
View a live demo!
Opening a Window Using Client-Side JavaScript
An example of this syntax can be seen in the following source code and in the associated live demo:
View the live demo! The above code will cause the URL to be loaded into a new window that is precisely 400 pixels wide and 400 pixels high.
The third parameter to the JavaScript
|
Home | FAQs | Articles | About | My Blog | Buy the Book!
Copyright 2006, Scott Mitchell. All Rights Reserved.