在两行之间插入行
我们使用 ASP.NET 1.1 进行网站开发,使用 DataGrid 控件显示数据。
有人可以建议我如何在数据网格控件中的两行之间插入行吗?
谢谢,
-纳伦德拉
We are using ASP.NET 1.1 for a website development, using DataGrid control for showing data.
Can some body suggest how can i insert rows in between two rows in datagrid control.
Thanks,
-Narendra
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将该行插入数据源(可能是数据表)中。
然后,您必须确保网格按您的要求排序。您希望新行位于特定位置,因此也许可以在 DataTable 上实现 SortOrder 列,并根据您的要求显式更新新行下方的所有行该列中的值,在绑定之前。
You'll have to insert that row in your data source - perhaps a DataTable.
Then you'll have to ensure that the grid is sorted as per your requirement. You're wanting the new row in a specific spot, so perhaps implement a SortOrder column on your DataTable, and explicitly update the values in that column for all the rows below the new row, as per your requirements, before binding.
您可以将新行插入到数据源(例如数据表)。
DataRowCollection 有一个函数 InsertAt ,可让您插入位于您想要的位置的行。
我将提供一个简单的示例(在带有 GridView 的 VB.Net 中,DataGrid 的工作原理相同):
ASPX:
代码隐藏:
You can insert the new row to the datasource (for example a DataTable).
DataRowCollection has a Function InsertAt that lets you insert rows at the position you want.
I will provide a simple example (in VB.Net with a GridView, DataGrid works the same):
ASPX:
Codebehind: