单击参数时在代码块中循环
基本上我想做的是显示类别列表。如果管理员已登录 我想在每个类别旁边显示一些按钮。例如删除按钮。问题是我不知道如何将参数传递给执行该操作的函数。
就像我指定在单击按钮时必须调用函数“DeleteCat”,但如果我无法传递要删除的类别的 ID,则这将不起作用。
我知道这可以通过命令和中继器来完成,但这不是一个选项,我不能使用中继器。
显然这就是我的目标:
但当然这是行不通的。
<%For Each Cat In Category.Children%>
<p class="SubCategory">
<%=Cat.Name%>
<%If User.Identity.Name = "Admin" Then%>
<asp:LinkButton ID="LinkButton6" runat="server" OnClick="AddItem" Text="A+" CommandArgument=<%=Cat.ID %> />
<%End If%>
</p>
<%Next %>
Basically what i am trying to do is display a list of categories. And if the admin is logged in
i want to show some buttons next to each category. For example a button to delete it. The problem is that i dont know how to pass a parameter to the function that does the action.
Like i specify that on button click the function 'DeleteCat' must be called but if i cant pass the ID of the category to be deleted this wont work.
I know this can be done with commands and a repeater, but its not an option, i cant use a repeater.
So apparanly this is what i am aiming for:
But of course it does not work.
<%For Each Cat In Category.Children%>
<p class="SubCategory">
<%=Cat.Name%>
<%If User.Identity.Name = "Admin" Then%>
<asp:LinkButton ID="LinkButton6" runat="server" OnClick="AddItem" Text="A+" CommandArgument=<%=Cat.ID %> />
<%End If%>
</p>
<%Next %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的事件处理程序 AddItem 应该能够评估事件的发送者 和 CommandEventArgs
在此处查看详细示例。
编辑
按照布兰登的建议完成了代码示例。
替代解决方案,使用 CheckBoxList
Your event handler AddItem should be able to evaluate the sender of the event and the CommandEventArgs
See detailed example here.
edit
Completed code sample as suggested by Brandon.
Alternative solution, using a CheckBoxList