获取在GridView使用LINQ和显示结果数据 [英] Get data using LINQ and show result in a gridview
本文介绍了获取在GridView使用LINQ和显示结果数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能从阵列中的所有模块如下图所示,其中学生名字,在C#和Asp.net使用LINQ。这件事情可能很容易做到,但都未能取得的伎俩。请帮忙。谢谢你。
How can I get all modules from the array like below where student firstName, using Linq in C# and Asp.net. It's something probably easy to do but have failed to get the trick. Please help. Thanks.
ArrayList arrList = new ArrayList(); //new array list for students
arrList.Add(
new Student
{
FirstName = "Svetlana",
LastName = "Omelchenko",
Password = "hh",
modules = new string[] { "001", "002", "003", "004" }
});
arrList.Add(
new Student
{
FirstName = "Claire",
LastName = "O’Donnell",
modules = new string[] { "001", "002", "003", "004" }
});
arrList.Add(
new Student
{
FirstName = "Sven",
LastName = "Mortensen",
modules = new string[] { "001", "002", "003", "004" }
});
arrList.Add(
new Student
{
FirstName = "Cesar",
LastName = "Garcia",
modules = new string[] { "HH", "KK", "LL", "OO" }
});
var query = from Student student in arrList
where student.FirstName == "Cesar"
select query;
GridView1.DataSource = query;
GridView1.DataBind();
我希望把结果在Asp.net网格表。请帮助!
I want to put the results in a grid table in Asp.net. Please help!!
推荐答案
您在您的查询的末尾缺少了ToList。
you are missing ToList at the end of your query.
yourGridView.DataSource = (from Student s in arrList
where s.FirstName == "Cesar"
select s).ToList();
然后将它绑定到你的GridView。
then bind it to your gridview.
这篇关于获取在GridView使用LINQ和显示结果数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文