Listview所选项目 [英] Listview Selected Item
问题描述
全部晚上,
我遇到了一个我无法解决的问题,我已经在线检查了,但似乎找不到我想要的答案.
我有一个正在使用搜索结果框的列表视图,例如,用户输入文本,单击搜索按钮,将搜索结果作为列表视图中的项目列表返回.
我想做的是单击每个项目时都选择它,并在按下按钮时执行一些代码.因此,例如,在这种情况下,我希望用户单击列表视图中的项目,然后单击添加到配置文件"按钮,该项目将被添加到配置文件中.
我不知道如何在列表视图中获取选定的项目,我真的很努力.我基本上是在尝试使用Listview的添加列创建列表框的功能.
任何帮助将不胜感激.
Dan
Evening All,
I have come across a bit of a problem that I can''t get around, I have checked online and I can''t seem to find the answer I am looking for.
I have a listview that is being used a search results box, for example user enters text, clicks search button, returns results of search as a list of items in the list view.
What I am trying to do is select each item when it is clicked on and do some code on a button press. So for example in this case I want a user to click on an item in the listview, click add to profile button and the item will be added to a profile.
I have no idea how you get the selected item in a listview and I am really struggling with it. I am basically trying to create the functionality of a listbox with the added columns of a Listview.
Any help would be much appreciated.
Dan
推荐答案
我不确定我是否以正确的方式遇到了问题,我认为您只需要为自己设置一个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());
}
}
}
这篇关于Listview所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!