1
votes

I use asp.net and have gridview control in aspx page. this gridview has not empty.

I have table name in page and want bind table to gridview. so:

gvName.DataSource =  dtName;
gvName.DataBind();

But with this code, Lost previous data in gridview. I went bind gvName.DataSource + dtName to gvName.

2
You have a two datasource and you want to combine them, after you want to set as datasource to gvName right ? - Soner Gönül
i have gvName (gridview), this not empty, so i have combine gvName and dtName (datatable) and bind this to gvName. - Ahmad Rezaye
What is your gvName default datasource? - Soner Gönül
datasource gvName has bind from database, but i not want combine database and datatable. - Ahmad Rezaye

2 Answers

0
votes

You would need to combine the rows on both data tables (the original source and the new data table) and then rebind the new data table containing all the rows.

In pseudo code:

DataTable t = GetInitialDataSource();
foreach(var item in newDataTable.Rows)
{
    t.ImportRow(item); 
}

gv.DataSource=t;
gv.DataBind();
0
votes

Try this code. DataTable.Merge cab be used to combines the datatables.

    dtName.Merge((DataTable)gvName.DataSource);
    gvName.DataSource = dtName;
    gvName.DataBind();