how to display empty table to datagrid
Answers were Sorted based on User's Feedback
Answer / dinesh sharma
DataTable tbl=new DataTable;
DataColumn ID=new
Datacolumn("ID",System.Type.GetType("System.Int"));
DataColumn Name=new
DataColumn("NAME",System.Type.GetType("System.String"));
tbl.Columns.add("ID");
tbl.Columns.Add("NAME");
Datarow dr =null;;
for (int i=0;i<100;i++)
{
dr=tbl.NewRow();
}
datagridview1.datasource=tbl;
Is This Answer Correct ? | 14 Yes | 1 No |
Answer / neha
DataTable tbl=new DataTable();
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Name");
datagridview.DataSource=tbl;
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / radhat
This works, but it only provides one empty row.
It doesn't give you 100 empty rows as your code suggests.
To fix this I added:
dr = tbl.Rows.Add();
right underneath the .NewRow(); line
Hope this helps anyone looking for an empty table.
Is This Answer Correct ? | 0 Yes | 3 No |
What is data view and variable view?
Whate are different types of Commands available with DataAdapter ?
What are the advantages using ado.net?
What is the meaning of executenonquery?
How many major types of connection objects in ADO.NET?
What is the difference between data grid and data repeater?
What are the two fundamental objects in ADO.NET?
What is difference in record set and dataset?
Which is faster dataset or datareader?
can u tell me the why ADO does not support xml..
What is ado connection?
What is the use of ADO.NET and XML web services?