Add row to datagrid without databinding again

G

Guest

Hi,

Is there a way to add a row to a datagrid after DataBind method is called. I
know I can call DataBind again, but that's not what I am looking for.

The reason I want to do this, I have a page to load data into a DataGrid and
let user edit data, now I want to add function for user to add data also.
The problem, this is All-Or-None situation, the user add/change several rows
then save all rows together or do nothing at all.

Thanks in Advance for any suggestions
 
G

Grant Merwitz

Not the ideal solution, but a work around.

When you say you don't want to databind it again, i take it you concerned
about the trip to the database.

So what you can do, is take the DataSource out of the DataGrid, add a new
row and rebind it. (avoiding a new trip to the database, but still
rebinding)

so if your grid was called MyGrid and it was Bound to a DataTable:

DataTable dt = (DataTable)MyGrid.DataSource; //for a DataSet --> DataSet
ds = (DataSet)MyGrid.DataSource;

//Add a new row to this datatable then rebind

MyGrid.DataSource = dt;
MyGrid.DataBind();

HTH
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top