Some time we see, a table have hyperlink column for URL. Here I have explained you how to achieve a column as hyperlink. DataGridView provide DataGridViewLinkColumn control through this we create a column as hyperlink.  Steps are given below.

Step 1: Create one windows application and drag-drop DataGridView control.

Step 2: Create a table in your database for demonstration. Below I have given my table structure. You can use this structure for creating table.

--Create database

-- Use database
--Create table
CREATE TABLE [dbo].[LinkDgvDemo]
[CompanyName] VARCHAR(100) NOT NULL,
[Website] VARCHAR(100)
-- Inser values
INSERT INTO [dbo].[LinkDgvDemo]([CompanyName],[Website]) VALUES('Mindstick Software Ptv. Ltd.',''),('Google',''),('Infosys',''),('Microsoft','')

 Step 3: Now bind your datagridview this table ([dbo].[LinkDgvDemo]). Read below link for binding database to datagridview.

Step 4: After binding database to datagridview, save and execute your application. Your application something looks as below image.

Hyperlink in DataGridView C#

Step 5: Now we create website column as hyperlink (red area of above image). Right click on DataGridView and select “Edit Cloumn…” option.

Hyperlink in DataGridView C#

Step 6: See below image of “Edit Column”.

Hyperlink in DataGridView C#

1.       Select website column.

2.       Select “DataGridViewLinkColumn” from ColumnType tag.

3.       Click button “OK”.

Step 7:  Now compare below image from step 4. All links are converted into hyperlink.

Hyperlink in DataGridView C#

Step 8:  Now we are going to create link action for open URL on web. Generate CellContentClick Event where we write line of code for open link column URL on webpage. Right click on datagridview. Select properties. Open datagridview event list and select CellContentClick event, as below image.

Hyperlink in DataGridView C#


Step 9: Copy below code and paste within “CellContentClick” in your windows form .cs file.

private void dgvControl_CellContentClick(object sender, DataGridViewCellEventArgs e)

            string sUrl = dgvControl.Rows[e.RowIndex].Cells[2].Value.ToString();
            ProcessStartInfo sInfo = new ProcessStartInfo(sUrl);

 Note: Rows[e.RowIndex].Cells[2], from above line of code,  ‘2’ are column index of hyperlink column that you change according your datagridview column. 

Run your application and see output.

  Modified On Nov-30-2017 12:10:53 AM
  1. Hi Patel,

    Thanks for your useful example. Its a bit useful to me. But in my winforms its some what different.

    I have a grid which should display multiple links within a single row, and when the blue link is clicked then the clicked cell's PDF should be opened..

    Awating for your reply

    Raghavendra Rao

Leave Comment