6
Answers

Add data to data grid

Carlos kambui

Carlos kambui

8y
336
1
dgv1.Rows.Add(txtname.text,txtAge.Text,txtGender.text) it underline Add with red what could be the problem
 
Answers (6)
0
ali tuncer

ali tuncer

NA 2.9k 108 8y

Vincent is right, I thought you were using DataGrid control in Winforms..

You could add rows to Datatable..set Datatable as your Datasource for datagrid...


 

0
Vincent Maverick Durano

Vincent Maverick Durano

NA 19.1k 2.2m 8y
DataGrid uses Items instead of Rows. 
 
If you want to add data to DataGrid then you need to add data to your DataSource instead of your DataGrid since the grid render the data based on your data source.
 
Check this link for example: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.items(v=vs.110).aspx 
0
Carlos kambui

Carlos kambui

NA 392 56.4k 8y
asp.net
 
0
ali tuncer

ali tuncer

NA 2.9k 108 8y
Is this Winform?, can you see Rows in intellisense after dgv1? 
0
Carlos kambui

Carlos kambui

NA 392 56.4k 8y
i have done and encountered this error
'System.Array' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) 
 
0
ali tuncer

ali tuncer

NA 2.9k 108 8y

parameters are wrong, try this way:

string[] testrow = new string[] { txtname.text,txtAge.Text,txtGender.text };
dgv1.Rows.Add(testrow);