I wish to show items that I have queried with LINQ on to the page.
我希望在页面上显示我与LINQ查询过的项目。
I can't seem to find any simple examples!
我似乎找不到任何简单的例子!
I have my query, TOELINE is my database name
我有我的查询,TOELINE就是我的数据库名
// Get the data context for the GROUP database
GroupDBDataContext db = new GroupDBDataContext();
// Query the database
var best_sellers = from bs in db.TOELINE
where bs.Company == "247HO001"
select bs;
How do I then within my .aspx
page, loop through the results and insert them where I wish, I know that I can output using a GridView but, I just want to loop through each record and show the different fields wherever I wish.
然后如何在。aspx页面中循环并插入结果,我知道我可以使用GridView输出,但是,我只想循环遍历每个记录并显示不同的字段。
So something like the below:
如下所示:
<div id="best_sellers">
<%
foreach (SingleRow in best_sellers)
{
// Show each row, the Company and ProductName fields
Response.Write("<div class=\"best_seller_row\">" + SingleRow["Company"] + " - " + SingleRow["ProductName"] + "</div>");
}
%>
</div>
I'm baffled that there aren't some simple examples like this. It seems dead easy with PHP.
我对没有这样简单的例子感到困惑。PHP看起来非常简单。
1 个解决方案
#1
1
Try this instead
试试这个相反
<%
foreach (var SingleRow in best_sellers)
{
// Show each row, the Company and ProductName fields
Response.Write("<div class=\"best_seller_row\">" + SingleRow.Company + " - " + SingleRow.ProductName + "</div>");
}
%>
You need to say what type the element in the foreach
loop is, or use var
to be lazy and let the compiler decide.
您需要说明foreach循环中的元素是什么类型,或者使用var让编译器决定是否懒惰。
#1
1
Try this instead
试试这个相反
<%
foreach (var SingleRow in best_sellers)
{
// Show each row, the Company and ProductName fields
Response.Write("<div class=\"best_seller_row\">" + SingleRow.Company + " - " + SingleRow.ProductName + "</div>");
}
%>
You need to say what type the element in the foreach
loop is, or use var
to be lazy and let the compiler decide.
您需要说明foreach循环中的元素是什么类型,或者使用var让编译器决定是否懒惰。