Home > DeveloperSection > Articles > Hyperlink in DataGridView C#

Hyperlink in DataGridView C#

C# C# 
2 Comment(s)
 23868  View(s)
Rate this:

Hyperlink in DataGridView C#

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.','http://mindstick.com'),('Google','http://google.com'),('Infosys','http://www.infosys.com'),('Microsoft','http://www.microsoft.com')


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.

Display of link

By Raghavendra Rao on   3 years ago
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

On Click of Hyperlink in DataGridView Open PDF file

By John Smith on   3 years ago
If you are using datagridview then on the click of hyperlink (click event) you will have to provide path of pdf file which you have to open.

Don't want to miss updates? Please click the below button!

Follow MindStick