How to Insert a MailTo Hyperlink in GridView
- 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();