首页 新闻 会员 周边

请问在mvc模式下,怎么从在xml里获得的字段名称进行排序

0
悬赏园豆:30 [已解决问题] 解决于 2012-07-27 09:38

请问在mvc模式下,在xml里获得的字段名称怎么对从存储过程查询出的具体数据进行排序

如xml

 <fields>
    <field text="产品">ProductCode</field>
    <field text="产品说明">ProductDescription</field>
    <field text="产品说明(英文)">ProductDescriptionEN</field>
    <field text="品牌">Brand</field>
 <fields>

现在要对从存储过程里面查出的产品,进行排序,请高手指导下,在线等,急,谢谢了!

涵若紫萱的主页 涵若紫萱 | 初学一级 | 园豆:175
提问于:2012-07-10 10:24
< >
分享
最佳答案
0

从存储过程里面查出的产品是什么类型?

收获园豆:6
dudu | 高人七级 |园豆:31003 | 2012-07-10 11:40

xml里面的东西主要是在前台显示具体的字段名称的,我现在要根据从数据库里面的值来排序,请问要怎么做了!

涵若紫萱 | 园豆:175 (初学一级) | 2012-07-10 13:03

@涵若紫萱: 数据库里面的值是用ADO.NET通过存储过程取出来的?按哪个字段进行排序?

dudu | 园豆:31003 (高人七级) | 2012-07-10 13:06

@dudu: 有多个字段,需要排序ProductCode,Brand

涵若紫萱 | 园豆:175 (初学一级) | 2012-07-10 13:17

@涵若紫萱: 需不需要分页?

dudu | 园豆:31003 (高人七级) | 2012-07-10 13:20

@dudu: 分页直接在存储过程里面实现了,现在因为是xml表示的字段名称,所以在mvc 下sort方法没有用,所以现在只要排序就行了,谢谢!

涵若紫萱 | 园豆:175 (初学一级) | 2012-07-10 16:16

@涵若紫萱: 如果只对当前页的内容进行排序,那将从存储过程得到的数据通过LINQ进行排序就行了。

dudu | 园豆:31003 (高人七级) | 2012-07-10 16:21
其他回答(4)
0

只要把数据用linq操作,就可以了哦。linq to xml。

收获园豆:6
無限遐想 | 园豆:3740 (老鸟四级) | 2012-07-10 10:32
0

用链表

View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
 
namespace SortChain
{
    public class SortChain
    {
        private string key = "";
 
        private ArrayList list = new ArrayList();
 
        private SortChain NextChain = null;
 
        public ArrayList SortList
        {
            get
            {
                list.Sort(IComparer());
                return list;
            }
        }
 
        public SortChain(string obj)
        {
            key = obj;
        }
 
        public void SetNextChain(SortChain chain)
        {
            this.NextChain = chain;
        }
 
        public SortChain GetNextChain()
        {
            return this.NextChain;
        }
    }
}

大概的思路是这样的

收获园豆:6
水晶途途 | 园豆:1443 (小虾三级) | 2012-07-10 10:35
0

把xml里的字段作为排序参数。对存储过程查询的实体对象结果用linq排序。

eg:

                switch (field)
                {
                    case "ProductCode":
                        query = query.OrderByDescending(m =>m.ProductCode);
                        break;
                    case "ProductDescription":
                        query = query.OrderByDescending(m => m.ProductDescription);
                        break;
                    case "ProductDescriptionEN":
                        query = query.OrderByDescending(m => m.ProductDescriptionEN);
                        break;
                    case "Brand":
                        query = query.OrderByDescending(m => m.Brand);
                        break;
                }

 

上面是倒叙。顺序就是query.OrderBy(m => m.xxx);

收获园豆:6
owsir | 园豆:481 (菜鸟二级) | 2012-07-10 10:36
0

var path = @"F:\vs\AWeb\TestProject2\XMLFile1.xml";
            XDocument xd = XDocument.Load(path); 

var query = from x in xd.Descendants("field")
                        select x;
            foreach (var item in query)
            {
                var name = item.Name;

      var value=item.Value;

      item.Attribute("text").Name;

      item.Attribute("text").Value;


            }你是要获取XML下的这些东西吗? 自己测试看看,问题我没怎么读懂。 祝你好运!

收获园豆:6
telang | 园豆:646 (小虾三级) | 2012-07-10 10:52

xml里面的东西主要是在前台显示具体的字段名称的,我现在要根据从数据库里面的值来排序

支持(0) 反对(0) 涵若紫萱 | 园豆:175 (初学一级) | 2012-07-10 13:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册