读书人

请教GridView怎么根据绑定的字段过滤。

发布时间: 2013-03-12 11:19:35 作者: rapoo

请问GridView如何根据绑定的字段过滤。用户名相同只要分数最高的那条数据。
请问如何根据它的memberSerials如果memberSerials字段相同只在GridView中显示同个帐号的最高分请教GridView怎么根据绑定的字段过滤。用户名相同只要分数最高的那条数据如图GridView数据从xml中读出,字段依次为:memberSerials、names、marks、times,经过DataSet数据使用过DataView将分数以大小排序,代码如下:

DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("xmls/tops20.aspx"));
XmlDocument doc = new XmlDocument();
doc.Load("xmls/tops20.aspx");
ds.Tables[0].Columns.Add("iPersonOrderSort", System.Type.GetType("System.Int32"));
ds.Tables[0].Columns["iPersonOrderSort"].Expression = "Convert(marks,'System.Int32')";
DataView tableview = ds.Tables[0].DefaultView;
tableview.Sort = "iPersonOrderSort desc";
GvList.DataSource = tableview;
GvList.DataBind();

请问如何根据它的memberSerials判断如果GridView中memberSerials字段有相同。只在GridView中显示同个帐号(memberSerials)的最高分。marks为分数。麻烦高人了,在下坐等结贴。
[解决办法]
引用:
引用:发错 marks最高的用户信息?
就是同一个用户marks最高的那个在GridView。
就是将GridView中相同用户的低分数过滤掉。

http://bbs.csdn.net/topics/20450903
参考吧
[解决办法]
我感觉先把ds的数据放到hashtable里,然后在绑定gridview。

hashtable ht = new hashtable();

for(int i=0;i<ds.table[0].rows.count;i++)
{
person p = new person ();
if(ht.contains(ds.table[0].rows[i]["memberSerials"].tostring()))
{
p = (person)ht[ds.table[0].rows[i]["memberSerials"].tostring()];
if(p.marks < ds.table[0].rows[i]["marks "].tostring())
{
p.marks = ds.table[0].rows[i]["marks "].tostring();
ht.remove(ds.table[0].rows[i]["memberSerials"].tostring());
ht.add(ds.table[0].rows[i]["memberSerials"].tostring(),P)
}
}
else
{
p.memberSerials = ds.table[0].rows[i]["memberSerials"].tostring();
p.names = ds.table[0].rows[i]["names "].tostring();
p.marks = ds.table[0].rows[i]["marks "].tostring();
p.times = ds.table[0].rows[i]["times "].tostring();
ht.add(ds.table[0].rows[i]["memberSerials"].tostring(),P)
}
}

不知道对不对瞎写的啊 感觉是是可以的

读书人网 >asp.net

热点推荐