动态添加行的GridView / DataGrid中/中继器? [英] Dynamically add row to GridView / DataGrid / Repeater?

查看:119
本文介绍了动态添加行的GridView / DataGrid中/中继器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个表,用户将完成其中有一个未知的行数。

I want to create a "table" that the user will complete which has an unknown number of rows.

要说明吧,让我们说这是从签收后的购物之旅进入细节 - 即行(或项目)的数量是未知

To illustrate it, let's say it is to enter details from a receipt after a shopping trip - i.e. the number of rows (or items) will be unknown.

要达致这我想创建一个单列一格,并包含文本框两列输入项目名称和价格:

To acheive this I want to create a grid with a single row, and two columns containing textboxes to enter the item name and price:

+ ------- + --------- +
  +产品+价格+
  + ------- + --------- +
  +豆+ 0.99 +
  + ------- + --------- +

+-------+---------+
+ Item + Price +
+-------+---------+
+ Beans + 0.99 +
+-------+---------+

然后第一行已经完成之后欲在运行中生成等另一行

Then after the first row has been completed I want to generate another row on the fly and so on.

这是该最佳的控制?是相当新的ASP.NET所以不知道我是否应该使用一个GridView / DataGrid中/中继器或者是什么。 (不知道是否有任何关联,但该项目texbox有一个Ajax AutoCompleteExtender关联。)

Which is the best control for this? Am fairly new to asp.net so not sure if I should be using a Gridview / DataGrid / Repeater or what. (Not sure if it has any relevance, but the item texbox has an Ajax AutoCompleteExtender associated.)

任何指针将是非常欢迎的。

Any pointers would be most welcome.

有一件事我忘了提及的是,在GridView(或其他)没有绑定到它的数据加载时。不知道这影响的决定。

One thing I forgot to mention is that the GridView (or whatever) has no data bound to it when it is loaded. Not sure if that impacts the decision.

推荐答案

GridView的是内联添加行不是很好。你可能需要做的东西有点哈克。你也许可以建立数据源网格视图,以便总有一个更空行以自己的真实数据的结束,然后只需确保您设置在网格中的最后一行是在编辑模式每次GridView控件绑定完毕。然后,你必须拦截的更新动作,使之真正插入,而不是更新。再有就是,你是否也想允许用户编辑现有的行了一个问题:编辑现有行,当你需要消除空行,因为你不能有两个可编辑排在同一时间。这是棘手的,但你也许可以做到这一点。

GridViews aren't really good at adding rows inline. You'll probably have to do something a little hacky. You might be able to set up the data source on your grid view so that there is always one more empty row at the end of your real data, and then just make sure that you set the last row in the grid to be in edit mode every time the gridview finishes binding. Then you'd have to intercept the Update action and make it actually Insert instead of updating. Then there's the question of whether you also want to allow the user to edit existing rows: when editing an existing row you'd need to eliminate the "empty" row because you can't have two editable rows at the same time. It's tricky, but you could probably do it.

另一种方法是使用一个中继器,以显示在最后以只读模式下,所有现有的行,然后就输出一个可编辑的行。

The alternative would be to use a repeater to show all your existing rows in read-only mode, and then just output an editable row at the end.

我不知道,我就选择在这一点上。

I'm not sure which I'd choose at this point.

这篇关于动态添加行的GridView / DataGrid中/中继器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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