如何在asp转发器中查找标签
我的 asp 的结构:repeater
repeater
updatePanel
label1 (rating)
button (updates rating)
some_picture (thing being rated)
/update panel
/repeater
想象一下上述中继器的输出包含 100 行。 (每行 1 个标签和 1 个按钮)。
目标:当我单击按钮时,我希望更新适当的标签。我不知道该怎么做。 我可以通过以下方式引用标签:
Label myLabel2Update = (Label)Repeater1.Controls[0].Controls[0].FindControl("Label1");
但是当然,每次都是相同的标签(不一定是需要更新的标签)。我需要更新与按钮位于同一行的标签。
任何指导将不胜感激。
Structure of my asp: repeater
repeater
updatePanel
label1 (rating)
button (updates rating)
some_picture (thing being rated)
/update panel
/repeater
Imagine the output of the above repeater containing 100 rows. (1 label, and 1 button on each row).
Goal: when I click the button, I want the appropriate label to be updated. I dont know how to do this.
I can reference a label via:
Label myLabel2Update = (Label)Repeater1.Controls[0].Controls[0].FindControl("Label1");
But ofcourse, it will be the same label each time (not necessarily the label that needs to be updated). I need to update the label that is on the same row as the button.
Any guidance would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
处理中继器的 ItemCommand 事件。在事件处理程序中,检查事件参数的 Item 属性并对其使用 findcontrol。例如,
Label1 将是与单击的按钮相同的项目中的标签。
或者响应 Dr. Wily 的学徒的评论,您可以执行以下操作
然后为每个按钮指定命令名称“bClick”
Handle the ItemCommand event of the repeater. In your event handler check the Item property of the event arguments and use findcontrol on that. e.g.
Label1 will be the label in the same item as the button that was clicked.
Or in response to Dr. Wily's Apprentice's comment you could do the following
And then for each button specify the command name "bClick"
您将需要一个辅助方法来遍历层次结构或使用
Control 的
FindControl(string id)
方法即可实现此目的。例子:
You will need a helper method to iterate through the hierarchy or use the
Control's
FindControl(string id)
method for that.Example:
我假设按钮有一个事件处理程序?如果是这样,你应该能够做到
I assume there's an event handler for the button? If so, you should be able to do