更新时间:2023-11-16 22:52:52
我不确定我是否以正确的方式遇到了问题,我认为您只需要为自己设置一个ItemCommand事件处理程序即可listview,然后在按钮(或任何其他控件)中设置CommandName和CommandArgument.
I''m not sure if I''ve got your problem in the right way, I think you just need to set an ItemCommand event handler for your listview and then set the CommandName and CommandArgument in your button (or in any other control).
<asp:listview runat="server" xmlns:asp="#unknown">
ID="TheAnimalsListView"
OnItemCommand="TheAnimalsListView_OnItemCommand"
DataKeyNames="TheID">
<layouttemplate>
[...]
</layouttemplate>
<itemtemplate>
<asp:linkbutton runat="server">
ID="SelectAnimalButton"
Text="Show This"
CommandName="ShowThis"
CommandArgument='<%#Eval("AnimalName")%>' />
</asp:linkbutton></itemtemplate>
</asp:listview>
然后,在后面的代码中
Then, in the codebehind
protected void TheAnimalsListView_OnItemCommand(object sender, ListViewCommandEventArgs e)
{
if (String.Equals(e.CommandName, "ShowThis"))
{
//Shows the image of the animal based on the AnimalName
ShowAnimalImage(e.CommandArgument.ToString());
}
}
}