In This Article I will Explain How to add Edit and Delete Button Links in DataGridView.
In my Pervious Article I Explained How to display Data in Datagridview and How to Set Auto Generate SNO in DataGridView.
Now i want to add link buttons to datagridview by using C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace DatagridviewExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { displayDataGridView(); DataGridViewLinkColumn Editlink = new DataGridViewLinkColumn(); Editlink.UseColumnTextForLinkValue = true; Editlink.HeaderText = "Edit"; Editlink.DataPropertyName = "lnkColumn"; Editlink.LinkBehavior = LinkBehavior.SystemDefault; Editlink.Text = "Edit"; dataGridView1.Columns.Add(Editlink); DataGridViewLinkColumn Deletelink = new DataGridViewLinkColumn(); Deletelink.UseColumnTextForLinkValue = true; Deletelink.HeaderText = "delete"; Deletelink.DataPropertyName = "lnkColumn"; Deletelink.LinkBehavior = LinkBehavior.SystemDefault; Deletelink.Text = "Delete"; dataGridView1.Columns.Add(Deletelink); } public void displayDataGridView() { SqlConnection con = new SqlConnection("Data Source = CHINNU;Initial Catalog = dotnetdb;Uid = sa;Password = password123;"); { SqlCommand cmd; cmd = new SqlCommand("select * from Employee", con); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.AutoGenerateColumns = false; dataGridView1.AllowUserToAddRows = false; int i = 1; foreach (DataGridViewRow row in dataGridView1.Rows) { row.Cells["SNO"].Value = i; i++; } } } } }OutPut: