Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add row to grid view

Is it possible to programmatically add a row to a GridView in C# ASP?

If yes, how ?

I want to add static data directly from the code, not from an array nor an datasource

like image 363
GmodCake Avatar asked Oct 08 '13 20:10

GmodCake


Video Answer


2 Answers

DataTable dt = new DataTable();
DataRow dr = dt.NewRow();
dr["Column1"] = string.Empty;
dt.Rows.Add(dr);

You can then bind your GridView to the DataTable...

gv.DataSource = dt;
gv.DataBind();
like image 161
Christian Phillips Avatar answered Oct 26 '22 06:10

Christian Phillips


dataGridView1.Columns[0].Name = "column1";
dataGridView1.Columns[1].Name = "column2";

string[] row1 = new string[] { "column1 value", "column2 value" };
dataGridView1.Rows.Add(row1);
like image 43
cvetyab Avatar answered Oct 26 '22 07:10

cvetyab