marcorenberg
asked on
Adding rows to an unbound GridView in ASP.Net 2.0
I would like to be able to populate the rows of a gridview at runtime, but I cannot figure out how.
I would expect to see a GridView1.Rows.Add() property, but it doesn't seem to exist.
I would expect to see a GridView1.Rows.Add() property, but it doesn't seem to exist.
I have the same problem ....
I have added the Row in the Datatable which bind to the gridview ,
after adding row just bind that datatable again to gridview
I have added the Row in the Datatable which bind to the gridview ,
after adding row just bind that datatable again to gridview
ASKER
digitalZo: I'm not familiar with the "DataSet" object they are using in that example. I would like to use a GridView.
The user is going to be adding/removing data from another control, and I want this to update my gridview. So I don't want to bind the gridview to a database.
There must be a way to manually add rows to a gridview, right?
The user is going to be adding/removing data from another control, and I want this to update my gridview. So I don't want to bind the gridview to a database.
There must be a way to manually add rows to a gridview, right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry the 3rd post. a typo.
ASKER
OK. I was having some trouble because it wouldn't allow me to do this:
DataRow dataRowObject = new DataRow();
I would get an error: "System.Data.DataRow.DataR ow(System. Data.DataR owBuilder) ' is inaccessible due to its protection level".
But got it working like this:
DataTable dt = new DataTable();
dt.Columns.Add("Name",Syst em.Type.Ge tType("Sys tem.String "));
dt.Columns.Add("Check1",Sy stem.Type. GetType("S ystem.Bool ean"));
object[] x = new object[2];
x[0] = "Marc";
x[1] = false;
dt.Rows.Add(x);
GridView1.DataSource = dt;
GridView1.DataBind();
Thanks for the help, digitalZo.
I do have another question: Some of my fields that I want to use are checkboxes, and when I run this, the checkboxes are disabled; I cannot change their values. I'll add a separate question for this.
DataRow dataRowObject = new DataRow();
I would get an error: "System.Data.DataRow.DataR
But got it working like this:
DataTable dt = new DataTable();
dt.Columns.Add("Name",Syst
dt.Columns.Add("Check1",Sy
object[] x = new object[2];
x[0] = "Marc";
x[1] = false;
dt.Rows.Add(x);
GridView1.DataSource = dt;
GridView1.DataBind();
Thanks for the help, digitalZo.
I do have another question: Some of my fields that I want to use are checkboxes, and when I run this, the checkboxes are disabled; I cannot change their values. I'll add a separate question for this.
https://www.experts-exchange.com/questions/22868478/Generating-column-names-dynamically.html