Hi
How to append data in existing Gridview. I have already data in gridview
Thanks
Hi
How to append data in existing Gridview. I have already data in gridview
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 26, 2023, 4:35 AM EDT
To append data in an existing
GridViewcontrol in ASP.NET, you can follow these steps:Get the data you want to append to the
GridView. This could be a single row or multiple rows of data.Create a new
DataTableobject and add the columns that match the columns in yourGridView.Add the new data to the
DataTableobject as rows.Merge the new
DataTablewith the existingDataTableof theGridView.Bind the merged
DataTableto theGridView.Example:
// Get the new data to append DataTable newDataTable = GetNewData(); // Create a new DataTable with matching columns DataTable existingDataTable = ((DataView)gridView.DataSource).Table; DataTable mergedDataTable = existingDataTable.Clone(); // Add new data to the DataTable foreach (DataRow newRow in newDataTable.Rows) { mergedDataTable.Rows.Add(newRow.ItemArray); } // Merge the new DataTable with the existing DataTable foreach (DataRow existingRow in existingDataTable.Rows) { mergedDataTable.ImportRow(existingRow); } // Bind the merged DataTable to the GridView gridView.DataSource = mergedDataTable; gridView.DataBind();