How to work with ASP.net GridView programmatically (i.e. without Data binding)?
A:
just set the DataSource property to the object you want to dispaly then call the DataBind method.
var items = new List<string> {"item1","item2","item3"};
GridView1.DataSource = items;
GridView1.DataBind();
Marwan Aouida
2009-07-05 18:28:12
-1 He mentioned NOT using data binding
Cody C
2009-07-05 18:34:54
I think he means by databinding "binding to the database" not the Databind method.
Marwan Aouida
2009-07-05 18:54:38
A:
There is no way to access the rows of the gridview like myGrid.Rows.Add().
You can update datasource before binding it to your gridview.
Canavar
2009-07-06 09:38:47
+1
A:
I like to use the DataTable, so I would do:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Include", typeof(Boolean));
dt.Columns.Add("Name", typeof(String));
dt.Rows.Add(new Object[] { 0, "Jim" });
dt.Rows.Add(new Object[] { 0, "Jen" });
dt.Rows.Add(new Object[] { 0, "Kylie" });
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
JBrooks
2009-07-15 02:57:36