I am having trouble fixing an error that I keep getting when I try to add a button column to my table. The error is: Argument 1: cannot convert from 'System.Windows.Forms.DataGridViewButtonColumn' to 'System.Web.UI.WebControls.DataControlField'
It is basically saying that I cannot use the local variable 'btn' in the line
gridViewStudent.Columns.Add(btn);
in the following code:
gridViewStudent.DataSource = table;
gridViewStudent.DataBind();
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
gridViewStudent.Columns.Add(btn);
btn.HeaderText = "Click Data";
btn.Text = "Click Here";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;
DataGridViewButtonColumn
intended to use with WinForms'DataGridView
control. In Web Forms context you may useButtonField
instead:Since there is no
Name
andUseColumnTextForButtonValue
properties present forButtonField
control, their assignments are just omitted.Alternatively you can use prepared
asp:ButtonField
insideColumns
section in ASPX page:Similar issue:
Programmatically Add ButtonColumn to GridView From DataTable