新行中ASP.NET GridView控件 [英] New row in ASP.NET GridView Control

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

问题描述

我想要做的很简单的东西,我似乎无法找到EnableClientAddRow财产,这样我就可以将其设置为true。我有一个Web窗体上的标准GridView控件。我想一个按钮出现在Web表单上。当用户点击该按钮,一个空行被添加到GridView UI,使用户可以在相应的字段中输入数据。该行将当然,有一些类型的保存按钮,在列。

I want to do something really simple, I just can't seem to find the EnableClientAddRow property, so I can set it to true. I have a standard GridView control on a web form. I want a button to appear on the web form. When the user clicks the button, an empty row is added to the GridView UI, so the user can enter data in the appropriate fields. The row will of course, have a "Save" button of some type in one of the columns.

我知道这个功能必须在GridView的地方,我只是无法找到它。我发现一些奇怪的黑客试图手工实现这一点。我不是在页脚或操作技巧的结合真正感兴趣的,只是标准添加行的方法。

I know this functionality must be in the GridView somewhere, I just can't find it. I did find some odd hacks that try to manually implement this. I'm not really interested in footer manipulations or binding tricks, just the standard add row method.

编辑:
看来在GridView不支持添加行作为第一顺序操作。这似乎是一个严重的设计缺陷。

It appears the GridView does not support adding a row as a first-order operation. This appears to be a serious design flaw.

推荐答案

我通常是基础数据源添加新记录的添加记录按钮点击操作的一部分。然后我为了显示空白行的观点重新绑定。

I typically add a new record to the underlying data source as a part of the "add record" button click action. I then re-bind the view in order to show the blank row.

新的记录通常如果GridView控件绑定到一个DataTable,或者一个对象,如果将GridView绑定到特定类型的集合的DataRow。不知道这是你考虑你的问题具有约束力的伎俩,但它运作良好,是相当容易实现。

The new record is typically a DataRow if the GridView is bound to a DataTable, or an object if the GridView is bound to a collection of a particular type. Not sure if that is what you consider a binding trick from your question, but it works well and is quite easy to implement.

编辑 - 详细描述这一过程:
该行添加到数据源,将EditItemIndex设置为新添加的行,以便该行进入编辑模式,然后绑定数据源到GridView。您EditItemTemplate中会包含取消和保存按钮。取消将GridView的底层数据源重新绑定没有空行,并设置EditItemIndex为-1,从而消除在GridView行。

Edit - more detail to describe the process: Add the row to the data source, set the EditItemIndex to the newly added row in order for the row to enter edit mode, then bind the data source to the GridView. Your EditItemTemplate would contain a Cancel and a Save button. Cancel would re-bind the GridView to the underlying data source without the empty row and set EditItemIndex to -1, thereby removing the row from the GridView.

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

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