Link to home
Start Free TrialLog in
Avatar of marcorenberg
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.

Avatar of digitalZo
digitalZo
Flag of India image

Avatar of Pratima
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
Avatar of marcorenberg
marcorenberg

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?


ASKER CERTIFIED SOLUTION
Avatar of digitalZo
digitalZo
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry the 3rd post. a typo.
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.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level".

But got it working like this:

     DataTable dt = new DataTable();
     dt.Columns.Add("Name",System.Type.GetType("System.String"));
     dt.Columns.Add("Check1",System.Type.GetType("System.Boolean"));
     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.