Ali  Alfaraj

Ali Alfaraj

  • NA
  • 68
  • 108.3k

Binding DataGridView to a DataTable

Sep 18 2014 8:17 AM
Dear Members,
 
I'm tyring to bind a DataGridView to a DataTable, but the DataGridView end up showning nothing! Below is the code.

Your great help and kind support is appreicated.

 

DataGridView dgv = new DataGridView();

 

DataTable dt=new DataTable();

dt.Clear();

dt.Columns.Add("Name");

dt.Columns.Add("Marks");

DataRow _ravi = dt.NewRow();

_ravi["Name"] = "ravi";

_ravi["Marks"] = "500";

dt.Rows.Add(_ravi)

DataRow _ravi1 = dt.NewRow();

_ravi1["Name"] = "ravi";

_ravi1["Marks"] = "500";

dt.Rows.Add(_ravi1);

dgv.DataSource = dt;


Answers (2)