How to add data to Datatable and show in grid view c#

China☆狼群 提交于 2019-12-11 23:25:00

问题


I need to add data to datatable and show it in a gridview. After entering each item, gridview should update automatically.

        DataTable obj_dt_grdvw = new DataTable();
        DataRow obj_dt_row = obj_dt_grdvw.NewRow();


        obj_dt_grdvw.Columns.Add("_Pur_Product_Id", typeof(string));
        obj_dt_grdvw.Columns.Add("Product_pur_Name", typeof(string));


        obj_dt_row["_Pur_Product_Id"] = _Pur_Product_Id;
        obj_dt_row["Product_pur_Name"] = Product_pur_Name;

        obj_dt_grdvw.Rows.Add(obj_dt_row);
        return obj_dt_grdvw;

After returning obj_dt_grdvw, all the data gets erased automatically from datatable. I would like to delete the data manually.

来源:https://stackoverflow.com/questions/20583546/how-to-add-data-to-datatable-and-show-in-grid-view-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!