Add Row to an existing GridView

G

Guest

Hi,

I have defined a gridview with header columns where 2 columns are normal
columns(boundFields) and other 2 columns as TemplateFields and I would like
to populate this grid with some data dynamically.
So, I used this code and it did add a row but with empty data in first 2
rows(boundFields).
DataTable dt = new DataTable();
dt = (DataTable)rolesGridView.DataSource;
dt.Columns.Add(new DataColumn("ID", typeof(string)));
dt.Columns.Add(new DataColumn("Role", typeof(string)));
DataRow dr = dt.NewRow();
dr["ID"]= "1";
dr["Role"] = "MyRole";
dt.Rows.Add(dr);

And it worked fine with a grid that I just dragged and dropped in form where
I didn't define any specifications in it.



Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top