重置网格视图中行的位置 [英] resetting the position of a row within gridview

查看:93
本文介绍了重置网格视图中行的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一种情况,即在页面加载时gridviewCountry已经与数据源通用列表(已排序的clist)绑定了.现在我必须在gridview中搜索特定的国家/地区,如果找到匹配项,那么必须在gridview的顶部显示该行.对于搜索,我使用了一个文本框来输入文本(即国家/地区名称),然后单击搜索按钮,则如果gridview中存在国家/地区,则应在上方的gridview的顶部显示其他国家/地区.这是我的要求.

I have a scenario such that gridviewCountry is already binded with datasource generic list<country>(clist which is sorted) at the time of page load.Now i have to search for a specific country in the gridview and if match found then have to display the row at the top of the gridview.For searching i have taken a textbox for entering the text(i.e. country name) and when clicked on search button then if country present in gridview then should display at the top of the gridview above other countries.This is my requirement.

推荐答案

我建​​议您创建一个函数,该函数将网格中的项目作为对象,并确定该国家/地区是否与特定国家/地区匹配,如果是,则返回false.那么gridview的ItemsSource将是linq语句:

I recommend that you create a function that takes the item in the grid and determines if the country matches the the specific country, returning false if it does. then the ItemsSource for the gridview would be a linq statement:

public Country ItemsSource
{
    get { return Countries.OrderBy(i => IsNotSelectedCountry(i)).ToList(); }
}



ToList()强制在存在PropertyChanged事件时更新列表.我从IsNotSelectedCountry 返回了false,因此不必进行递减运算.



The ToList() forces the list to be updated when there is a PropertyChanged event. I return a false from IsNotSelectedCountry so that I do not have to do a decending.


此代码项目文章

带有搜索选项(SearchableGridView)的ASP.NET GridView [ ^ ]

可能对您有帮助
This Code Project article

ASP.NET GridView with search option (SearchableGridView)[^]

may be helpful to you


这篇关于重置网格视图中行的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆