Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: ASP
Posted by: Mario Lopes
Added: Sep 15, 2018 3:36 PM
Views: 8
Gridview com lista dinamica sem sqldatasource
  1. DataTable dt = new DataTable();
  2.         DataColumn column = new DataColumn();
  3.         dt.Columns.Add("ID", typeof(Int32));
  4.         dt.Columns.Add("Name", typeof(string));
  5.         dt.Columns.Add("Last Name", typeof(string));
  6.         for(var a=1;a<5;a++)
  7.         {
  8.             DataRow row = dt.NewRow();
  9.             row[0] = "12";
  10.             row[1] = "Pires";
  11.             row[2] = "lopes";
  12.             dt.Rows.Add(row);
  13.         }
  14.         GridView1.DataSource = dt;
  15.         GridView1.DataBind();
  16.  
  17. Segunda opção
  18.         GridView1.DataSource = new List<dynamic>() {
  19.             new { Name = "Andy", LastName="Wayne", Position = "PG"},
  20.             new { Name = "Bill", LastName="Johnson", Position = "SD" },
  21.             new { Name = "Caroline", LastName="Barry", Position = "Manager"}
  22.         };
  23.         GridView1.DataBind();