How to Insert a MailTo Hyperlink in GridView
The Microsoft .NET GridView control lets you create rows of information dynamically. The GridView is used in several online applications, because the control gives you the ability to customize its information and data to fit your app's requirements. You load the GridView control in the Web page's "OnLoad" event, which runs each time the user opens the Web page. You use the .NET "HyperlinkField" control to display the link.
Instructions
-
-
1
Open the Visual Studio software and open the Web project for your online application. Double-click the source code file you want to use to edit the GridView content.
-
2
Create a DataTable control and add a row for the HyperlinkField. The DataTable contains the data for the GridView, and you later bind the DataTable to the GridView to display the data. The following code creates the DataTable and creates the row:
DataTable dt = new DataTable();
DataRow dr = null;
dr = dt.NewRow(); -
-
3
Create the HyperlinkField control. The following code creates the HyperlinkField and add the link to the control:
HyperLinkField link = new HyperLinkField();
link.NavigateUrl = "mysite.com";Replace "mysite.com" with the URL for the hyperlink.
-
4
Add the HyperlinkField to the DataRow object. The following code adds the hyperlink and add the row to the table:
dr["link"] = link;
-
5
Bind the DataTable to the GridView, which displays the link to the user. The following code binds the table:
Gridview1.DataSource = dt;
Gridview1.DataBind();
-
1