简体   繁体   English

动态将行添加到GridView

[英]Adding rows to gridview dynamically

如何使用c#asp.net将数字行动态添加到网格视图

To do this, add rows to the data source to which the grid is bound. 为此,向网格绑定到的数据源添加行。

Here's an example. 这是一个例子。

Edit: The link I posted adds a row without adding to the data source. 编辑:我发布的链接添加一行而不添加到数据源。 It seems kind of kludgey to me, but it may be more like what you're looking for. 在我看来,这有点不合时宜,但可能更像您想要的东西。

Add new "rows" to the datasource of the grid. 将新的“行”添加到网格的数据源。 If your datasource is a DataTable, then add a new DataRow to the DataTable. 如果您的数据源是一个数据表,则向该数据表添加一个新的数据行。 If your datasource is a collection of objects, then add a new object to that collection. 如果您的数据源是对象的集合,则向该集合添加一个新对象。

Don't forget to rebind the grid once you have updated the datasource. 更新数据源后,不要忘记重新绑定网格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM