如何单击即可在网格视图中保存多个记录 [英] How to save multiple records in grid view using single click

查看:62
本文介绍了如何单击即可在网格视图中保存多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web表单,在从Web表单在grid_view中添加一些记录后,我想通过临时表将数据插入到gridview中,我想单击一下即可将所有数据保存在数据库中,假设我的表中有5列(数据库),只有Gridview中的三列和Webform中的两列,单击所有行和5列,在同一列(如date或ProductReceivedBy)中具有相同记录的2列,以及网格中的三列.任何机构都可以帮助我找出此代码的解决方案.我正在使用VS2005和SQLServer2005.任何机构都可以为我提供代码....

I have a webform and I am able to insert data into gridview using temporary table after adding Some records in grid_view from the webform i want to save all the data in database in a single click, Suppose i have 5 column in my table(Database) and only three column in Gridview and two column in webform, in single click all the rows and 5 column, 2 column with same record in the same column like date or ProductReceivedBy and three column from the grid. Can any body help me to find out the solution of this code. I am using VS2005 and SQLServer 2005. Can any body provide me code....

推荐答案

有很多技术可以做到这一点.为此,

方法1.您可以使用XML-在前端创建一个DataTable并从该数据表创建xml,然后将此xml作为参数发送给sp.

方法2.在sp中采用5个参数,对于表单值采用2个参数,对于网格值采用3个参数.这三个是varchar(max).在前端,使用foreach为每个列创建一个逗号分隔的字符串,并发送给每个参数,然后在sp中,使用split函数将3个参数拆分为表格.
那么您可以在SP中使用循环在表中插入记录.我正在使用第二种方法,并且如果正确理解,将可以正常工作. :-)
Hi, There is many techniques for doing this. for this,

Method 1. You can use XML- Create a DataTable at front end and create xml from that data table and send this xml as a parameter to sp.

Method 2. take 5 parameters in sp, 2 for form values, and 3 for grid values. these 3 are varchar(max). at Front end, using foreach make a comma separated string for each column and send to each parameter then in sp, split 3 parameters into tables using split function.
then you can use loop in SP for inserting record in table. I am using 2nd method and works right if understood properly. :-)


一种方法是通过在编辑模式下加载gridview.
然后在页面上有一个按钮,并在单击时设置此方法:
One way you can do that is by loading the gridview in edit mode.
Then you have a button on the page and set this method on click:
protected void Button1_Click(object sender, EventArgs e)
  {
      for (int i = 0; i < GridView1.Rows.Count; i++)
      {
          GridView1.UpdateRow(i, false);    //save the row at index = i

      }
  }


这篇关于如何单击即可在网格视图中保存多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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