如何将Gridview单元格插入表格 [英] How to insert Gridview cell to table

查看:154
本文介绍了如何将Gridview单元格插入表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将网格视图的所有单元格值插入到.mdb文件中。但是它只能插入gridview的页面大小。如果gridview的页面大小为20,那么它只能够仅插入20条记录。如何插入gridview的所有行。





I want to insert all the cell value of a grid view into a .mdb file.But the it can only able to insert only the page size of the gridview.if the page size of gridview is 20 then it can only able to insert 20 records only.How to insert all the rows of gridview.


foreach (GridViewRow g1 in GVSalDet.Rows)
               {
                   string insertsql = string.Format("insert into RepTab ( EmpID, EmpName GName,DName,CName,Sal,Ptax) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}' )", g1.Cells[1].Text.ToString(), g1.Cells[2].Text.ToString(), g1.Cells[3].Text.ToString(), g1.Cells[4].Text.ToString(),
                              g1.Cells[5].Text.ToString(),float.Parse(g1.Cells[6].Text.ToString()),float.Parse(g1.Cells[7].Text.ToString()));

                   module.ReportNonQuery(insertsql);
               }







ReportNonQuery是类文件




ReportNonQuery is class file

推荐答案

在循环之前设置 AllowPaging = false 并重新绑定 GridView

Before Looping set AllowPaging = false and rebind the GridView.
GVSalDet.AllowPaging = false;
GVSalDet.DataBind();


您应该更改类似的代码

You should change your code something like this
int count=0;int pagesize=20;
<pre lang="cs">foreach (GridViewRow g1 in GVSalDet.Rows)
               {
if(count <= pagesize){
                   string insertsql = string.Format("insert into RepTab ( EmpID, EmpName GName,DName,CName,Sal,Ptax) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}' )", g1.Cells[1].Text.ToString(), g1.Cells[2].Text.ToString(), g1.Cells[3].Text.ToString(), g1.Cells[4].Text.ToString(),
                              g1.Cells[5].Text.ToString(),float.Parse(g1.Cells[6].Text.ToString()),float.Parse(g1.Cells[7].Text.ToString()));

                   module.ReportNonQuery(insertsql);
          count +=1;
}               }


这篇关于如何将Gridview单元格插入表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆