asp.net排序内部的ListView [英] asp.net Sorting an inner ListView

查看:141
本文介绍了asp.net排序内部的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只使用asp.net约一个月,所以我现在希望我的白话是有道理的。我宁愿preFER使用MVC,但这个特殊的视图页看似已被使用ASPX和code隐藏文件,因为它需要被包含在平面文件CMS。

I've only been using asp.net for about a month now so I hope my vernacular makes sense. I would much rather prefer to use MVC but this particular view page seemingly has to be using aspx and code-behind files as it needs to be "included" in a flat-file CMS.

我有3个嵌套的列表视图。首先是从我的$ C $使用LINQ填充(数据绑定)C-隐藏文件和伟大工程,获取的多年的列表的。然后第二的ListView我调用一个函数Ge​​tRecordsFromYear它可以获取所有的记录的,再次使用LINQ在code-落后。

I have 3 nested ListViews. The first is populated (databound) from my code-behind file using LINQ and works great, gets a list of years. Then for the second ListView I call a function GetRecordsFromYear which gets all the records, again using LINQ in the code-behind.

<asp:ListView ID="lv2" runat="server" DataSource='<%# GetRecordsFromYear(Convert.ToInt32(Container.DataItem)) %>'>

接着,对于每个记录的有一个导航属性​​(一到许多与另一个表的关系)用的的。在的表中有一个名为gradyear一栏是我想通过这最后的ListView排序的。我可以输出这个细做是这样的:

Next, for each Record there is a navigation property (one-to-many relationship with another table) with Degrees. The Degrees table has a column named "gradyear" which is what I want to sort this last ListView by. I can output this fine by doing something like:

<asp:ListView ID="lv3" runat="server" DataSource='<%# Eval("Degrees") %>'>

一切完美的作品,除了我无法弄清楚如何排序这最后的ListView。我不能使用LINQ,因为我从来没有真正获取这些数据,这是第一个表的导航属性的记录的。我想我很可能只是用另一个函数来检索数据,但它似乎愚蠢到要保持查询数据库中的所有的时候,我已经提供给我的导航属性。我不想一个按钮来进行排序,只是它已经默认排序。

Everything works perfectly except I can't figure out how to sort this final ListView. I can't use LINQ because I never really retrieved this data, it's a navigation property of the first table Records. I guess I could probably just use another function to retrieve the data but it seems silly to have to keep querying the database all the time when I have the navigation property available to me. I don't want a button to sort it, just have it sorted by default.

推荐答案

你试过:

<asp:ListView ID="lv3" runat="server" DataSource='<%# From o in Eval("Degrees") order by o.gradyear %>'>

选项2:
如果的eval(度)是一个IEnumerable,你可以这样做

Option 2: If Eval("Degrees") is an ienumerable you can do something like

  <asp:ListView runat="server" ID="lstInner" DataSource='<%#  GetDegrees(Eval("Degrees")) %>'>

VB端:

 Public Function GetDegrees(degrees As IEnumerable) As IEnumerable
    Return From o In degrees Order By o.gradyear
End Function

这篇关于asp.net排序内部的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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