Rahul J

Rahul J

  • NA
  • 1
  • 576

Data grid is not populated with data from data table

Jun 19 2016 1:02 PM

I have created a data grid view, i have also created a data table with values now i want to add the whole data table to data grid view.

So here is my code // dataGrid is creditMemoGrid
 
creditMemoGrid.Columns[0].Name = "No.";
creditMemoGrid.Columns[1].Name = "Memo #";
creditMemoGrid.Columns[2].Name = "Amount";
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
// Here we add five DataRows.
table.Rows.Add(25, "Indocin", "David");
table.Rows.Add(50, "Enebrel", "Sam");
table.Rows.Add(10, "Hydralazine", "Christoff");
table.Rows.Add(21, "Combivent", "Janet");
table.Rows.Add(100, "Dilantin", "Melanie");
creditMemoGrid.DataSource = table; // no data in data grid
 

If i do "creditMemoGrid.DataSource = table" i dont see data in data grid. what is the problem that i am facing ?

Can anybody help me?

 

Answers (1)