Webforms 中继器链接问题
我有一个中继器,其中一列中有一个 LinkButton,并且连接了 onclick 事件。当用户单击其中一个选项时,我需要知道他们单击了哪个 LinkButton。执行此操作的最佳做法是什么?
I have a repeater that has a LinkButton in one of its columns and I have the onclick event wired up. When the user clicks on one of the options, I need to know in the event which LinkButton they clicked on. What is the best practice to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用
OnCommand
事件而不是OnClick
使用一些CommandName
和CommandArgument
来区分黑白项目。 此 MSDN 页面例子。You should use the
OnCommand
event instead ofOnClick
use someCommandName
andCommandArgument
to distinguish b/w items. This MSDN page has an example.通常
CommandArgument='<%#Eval("Id")
用于此类目的,然后它会像...
Normally
CommandArgument='<%#Eval("Id")
is used for such purposeand then it will be like...
您想要做的是连接 Repeater 的
ItemCommand
事件,而不是使用 LinkButton 的OnClick
事件。而是连接 LinkButton 的CommandName
。当 ItemCommand 触发时,您将能够根据按钮上设置的
CommandName
判断哪个按钮触发了它。您还可以访问中继器该行中的所有控件。微软软件定义网络
http://msdn.microsoft.com /en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx
What you want to do is wire up the Repeater's
ItemCommand
event and not use the LinkButton'sOnClick
event. Instead wire up theCommandName
of the LinkButton.When the ItemCommand fires you'll be able to tell what button triggered it based on the
CommandName
that was set on the button. You'll also have access to all the controls in that row of the Repeater.MSDN
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx
检查此代码
源URL http://forums.asp.net/p/1062060/1528071 .aspx
Check with this code
Source URL http://forums.asp.net/p/1062060/1528071.aspx