ASP.NET +网格视图命令字段作为模板字段
我有一个网格视图。我的 GridView 有一个包含“选项”列的列。此列包括传统的 CommandField 选项(编辑、删除等)。我的代码设置可以在使用 CommandField 时工作。但是,我需要进行一些自定义格式设置,因此我需要将 CommandField 转换为 TemplateField。
我的问题是,如何从 TemplateField 中的各个 LinkButton 元素触发 OnRowCommand、OnRowEditing、OnRowDeleting 和 OnRowUpdating 事件?
谢谢你!
I have a GridView. My GridView has a column that is contains an "Options" column. This column includes the traditional CommandField options (edit, delete, etc.). I have the code setup to work when a CommandField is used. However, I need to do some custom formatting so I needed to convert the CommandField to a TemplateField.
My question is, how do I trigger the OnRowCommand, OnRowEditing, OnRowDeleting, and OnRowUpdating events from the various LinkButton elements in my TemplateField?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您所要做的就是将模板列内的 LinkButton 的 CommandName 属性设置为“编辑”以进行编辑,“删除”以进行删除,“更新”以进行更新。这将分别触发 GridView RowEditing、RowDeleting 和 RowUpdating 事件。要触发 RowCommand 事件,您需要设置 GridView 控件的 OnRowCommand 属性。
All you have to do is set the CommandName property of the LinkButton inside of your template column to 'Edit' for editing, 'Delete' for deleting and 'Update' for updating. This will trigger the GridView RowEditing, RowDeleting and RowUpdating events respectively. To trigger the RowCommand event you need to set the OnRowCommand property of your GridView control.
我也有同样的问题。
对于编辑,我做了以下操作:
这允许显示/隐藏更新和取消按钮。
至于删除,我使用了以下内容:
I had the same problem.
For edit, I did the following:
This allows for the showing/hiding of the update and cancel buttons.
As for delete, I used the following:
单击属性中的“列”,添加
CommandField(Edit,update,Cancel)
并单击“将此字段转换为 templateField”,切换到源并自动添加代码。
click on Columns in properties, add
CommandField(Edit,update,Cancel)
and Click on the "Convert this field to templateField"Swich to Source and automatically going to add a code.