【发布时间】:2011-05-01 14:57:25
【问题描述】:
我需要将 LINQ 查询绑定到 gridview 的行。我正在尝试创建一个类似于 expedia 中的矩阵的表格,其中在不同的行上有不间断、1 个停靠点和 2 个停靠点。我不太确定如何将查询绑定到 gridview 行。感谢您的帮助。
var imgquery = from f in XElement.Load(MapPath("flightdata3.xml")).Elements("flight")
orderby Convert.ToInt32(f.Element("price").Value)
select new
{
ImagePath = (string)f.Element("airlineimageurl").Value
};
//query for gvMatrix where numberofstops=0
var numstops0query = from f in XElement.Load(MapPath("flightdata3.xml")).Elements("flight")
where Convert.ToInt32(f.Element("numberofstops").Value) == 0
orderby Convert.ToInt32(f.Element("price").Value)
select new
{
Price = "$" + (Int32)f.Element("price"),
ImagePath = (string)f.Element("airlineimageurl").Value
};
<asp:GridView ID="gvMatrix" runat="server">
</asp:GridView>
【问题讨论】:
-
你的意思是每一行都要绑定不同的数据集吗?
-
请提供一些代码示例说明您正在尝试做什么
-
我的意思是每一行都会绑定到不同的查询。这有意义吗?每行会有不同的 where 条件,例如 where nonstop=0, nonstop=1, nonstop=2
-
请提供一些代码以便我们为您提供帮助。
-
我将我的代码添加到原始帖子中。
标签: c# asp.net linq linq-to-objects