添加新行到GridView控件没有的DataBind [英] Add New Row to GridView without DataBind

查看:168
本文介绍了添加新行到GridView控件没有的DataBind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许编辑值每一列,每一行的GridView,所有的时间。用户在其所有的变化进入,点击保存一次,所有的变化上犯下。

I have a GridView that allows editing the values in every column, in every row, all the time. The user enters in all their changes, clicks Save once and all changes are commited.

用户还必须能够单击新建按钮,有一个新行出现在GridView(是的,它在实际GridView的展现出来),进入任何他们想要的数据,单击保存,并拥有所有的变化去到数据库中。

The user must also be able to click the New button, have a new row appear in the GridView (yep, it has to show up in the actual GridView), enter whatever data they want, click Save and have all changes go to the database.

现在。这里是一个的扔我的用户案例:用户到达页面,使几个现有行数的变化,则需要添加一个新行,在新行中输入数据,单击保存,都改变访问数据库

Now. Here's the user case that's throwing me: a user arrives at the page, makes several changes on several existing rows, and then needs to add a new row, enter data in the new row, click Save, and have all changes go to the database.

不过,我见过的唯一的方式来添加新的空行涉及重新绑定的GridView,这意味着他们所有的修改都将丢失。这显然​​是没有好处的。

However, the only ways I've seen to add a new, empty row involve rebinding the GridView, which means all of their changes will be lost. This is obviously no good.

所以,我的问题是:什么是一些方法来添加一个新的空,可编辑行的GridView,而无需重新绑定GridView的

So, my question would be: what are some approaches to adding a new, empty, editable row to a GridView without having to rebind the GridView?

我能想到的唯一的事情是,在新按钮的单击事件,吸所有的数据出来GridView控件(包括用户的潜在修改)中,将其保存到ViewState中(或其他),添加新行,重新填充网格。这对我来说,似乎有点哈克,但它应该让我关闭ViewState在GridView上。

The only thing I can think of would be, on the New buttons' click event, suck all the data out of the GridView (including the user's potential edits), save it to ViewState (or whatever), add the new row, repopulate the grid. This, to me, seems a little hacky, but it should allow me to turn ViewState off on the GridView.

任何想法?

推荐答案

只是把我的头,我能想到的两种选择。首先是缓存您绑定到网格中的原创性成果,当你需要添加另一行添加一个数据行到你绑定,然后绑定这对电网的datatabale。如果有网格的变化,那么你需要更新的数据表。一旦所有已经作了修改,用户点击保存按钮,您可以通过表遍历和更新数据库与数据。

Just off my head I can think of two options. The first is to cache the original results that you are binding into the grid and when you need to add another row you add a datarow to the datatabale that you are binding to and then bind this to the grid. If there are changes in the grid then you need to update the datatable. Once all changes have been made and the user clicks the save button you can iterate through the table and update the DB with the data.

它看起来像这样

页面加载


  • 获取DB数据并放入表

  • 绑定表向电网

  • 存储表在缓存

当用户请求一个新行


  • 获取缓存的数据对象。

  • 更新已更改的任何行

  • 一个空行绑定添加到网格

当用户保存网格


  • 获取缓存的对象。

  • 请最后一组更新

  • 循环遍历行和更新数据库

另一种方式做,这是由动态创建格,但是比它的价值给你描述一下这个会涉及更为努力。

The other way to do this is by creating the grid dynamically but this will involve far more effort than it's worth given what you have described.

这篇关于添加新行到GridView控件没有的DataBind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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