如何在ASP.NET C#中将gridview转换为datatable? [英] How to convert gridview to datatable in ASP.NET C#?
本文介绍了如何在ASP.NET C#中将gridview转换为datatable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i have upload one excel file and convert into datatable and bind the datatable in gridview.
i have one button click to add new row in grid view. i want get old data into datatable and adding new row how to do it.
i have used below codes to get grid view to data table but this is not working.that codes add only new row old rows are remove or hided.
我尝试过:
What I have tried:
sample1
DataTable gridTable = (DataTable) dataGrid1.DataSource;
sample 2
BindingSource bs = (BindingSource)dgrid.DataSource; // Se convierte el DataSource
DataTable tCxC = (DataTable) bs.DataSource;
sample 3
DataTable dt = new DataTable();
for (int i = 0; i < GridView1.Columns.Count; i++)
{
dt.Columns.Add("column"+i.ToString());
}
foreach (GridViewRow row in GridView1.Rows)
{
DataRow dr = dt.NewRow();
for(int j = 0;j<GridView1.Columns.Count;j++)
{
dr["column" + j.ToString()] = row.Cells[j].Text;
} dt.Rows.Add(dr);
}
推荐答案
请参阅以下链接,以帮助您的查询解决:
asp.net - 向行添加行c#中的数据表 - Stack Overflow [ ^ ]
Please see the link below which will help your query to solve:
asp.net - Adding rows to the Datatable in c# - Stack Overflow[^]
这篇关于如何在ASP.NET C#中将gridview转换为datatable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文