启用分页时在 asp.ListView 中查找具有 Value 的项目
我试图在单独页面上的 aspx ListView 中找到选定的项目,然后切换页面并选择该项目。我有我正在寻找的 ListViewItem 的 value 属性,但似乎无法让它工作。这是我尝试过的:
for (int i = 0; i < lvProject.Items.Count; i++)
{
if (((Label)lvProject.Items[i].FindControl("Project_IDLabel")).Text == project.ToString())
{
lvProject.SelectItem(i);
break;
}
}
所以 lvProject 是我的列表视图。项目变量是一个 Int64,代表我的项目的 UID。这也是我的 ListViewItems 的值。上面代码的问题是,当启用分页并且项目位于不同页面上时,这将不起作用,因为 listView.Items.Count 仅设置为当前页面上的项目数。
我的目标是找到该项目,将列表视图设置为显示正确的页面,最后选择该项目。您可能会认为我可以只设置 SelectedValue 属性,但这并不那么简单,因为它是只读的。任何想法都会有很大帮助,提前致谢。
——罗马
I'm trying to find the selected Item in an aspx ListView that is on a separate page, then switch the page and select the item. I have the value property of the ListViewItem I am looking for, but cannot seem to get it to work. Here is what I tried:
for (int i = 0; i < lvProject.Items.Count; i++)
{
if (((Label)lvProject.Items[i].FindControl("Project_IDLabel")).Text == project.ToString())
{
lvProject.SelectItem(i);
break;
}
}
So lvProject is my list view. The project Variable is an Int64 which represents the UID of my Project. This is also the Value of my ListViewItems. The problem with the code above is that when paging is enabled, and the item is on a different page this will not work because the listView.Items.Count is set to the # of Items on the current page only.
My goal is to find the item, set the listview to display the correct page, and finally select the item. You would figure that I could just set the SelectedValue property, but this is not that simple as it is read only. Any ideas would help greatly, thanks in advance.
--Roman
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了从对象数据源获取总记录数,您应该使用 Selected 事件,如下所示:
然后您将能够按如下方式搜索项目:
希望它有帮助!
In order to get the total record count from the object data source, you should use the Selected event as follows:
You would then be able to search for the item as follows:
Hope it helps!
如何绑定ListView项目?
How do you bind ListView Items?
您应该将
SelectedIndex
属性设置为i
You should set the
SelectedIndex
property toi