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 ado in agriculture?
What is concurrency? How will you avoid concurrency when dealing with dataset? (One user deleted one row after that another user through his dataset was trying to update same row. What will happen? How will you avoid the problem?)
What is the provider and namespaces being used to access oracle database?
Where do you store connection string ?
What are the different namespaces used in the project to connect the database? What data providers available in .net to connect to database?
If a table contains 20000 records . In a page at each time 100 records to be displayed what are the steps you will take to improve performance? Will you use dataset or datareader?
Compare Data Reader & Dataset in ado.net?
What is connection string?
Is it possible to load multiple tables in a Dataset?
Differences between dataset.clone and dataset.copy?
What is ado.net tutorial?
What is sqldatasource?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)