ASP 使用var类型时只显示第一个gridview

ASP only shows the first gridview when var type is used

我只是 ASP 和 C# 的初学者。当运行下面有两个GridView时,刚进入default.aspx页面的Gridview1。还尝试在 aspx 代码中定义 DataSourceId 但没有成功。看起来 ASP 只显示在代码中找到的第一个 gridview 而忽略了第二个。非常感谢您的帮助!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using CsvHelper.TypeConversion;
using CsvHelper;
using System.IO;
sing CsvHelper.Configuration;
using System.Data;
using System.Windows;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        StreamReader sr = new StreamReader(Server.MapPath(@"MAD-DC01.MAD-TEST.ES.201808.csv"));
        CsvReader csvread = new CsvReader(sr);

        IEnumerable<TestRecord> record = csvread.GetRecords<TestRecord>();
        var Prints = from t in record     
                     group t by new { t.Airline, t.Kiosk_name,t.Type_print } into grupo
                     orderby grupo.Key.Airline ascending
                     select new
                            {
                                 Aerolinea = grupo.Key.Airline,
                                 Kiosko = grupo.Key.Kiosk_name,
                                 Impresion=grupo.Key.Type_print,
                                 cuenta = grupo.Sum(x => x.Prints_outs),
                            };
    var Total_Prints = from t2 in record
                       group t2 by new { t2.Airline,t2.Type_print } into grupo2
                       orderby grupo2.Key.Airline ascending
                       select new
                              {
                                  Aerolinea = grupo2.Key.Airline,
                                  Impresion = grupo2.Key.Type_print,
                                  cuenta = grupo2.Sum(x => x.Prints_outs),
                              }; 

    GridView1.DataSource = Prints.ToList();
    GridView1.DataBind();

    GridView2.DataSource = Total_Prints.ToList();
    GridView2.DataBind();
}

public class TestRecord // Test record class
{
    public DateTime Date { get; set; }
    public string Airport { get; set; }
    public string Type_print { get; set; }
    public string Airline { get; set; }
    public string Kiosk_name { get; set; }
    public Int32 Prints_outs { get; set; }

}

这是 aspx 部分:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form runat="server">
 <div>

     <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1">
     </asp:GridView>
     <asp:GridView ID="GridView2" runat="server" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
     </asp:GridView>
     <br />

 </div>
</form>
</body>
</html>

我已经通过更换

解决了这个问题
IEnumerable<TestRecord> record = csvread.GetRecords<TestRecord>();  

作者:

List<TestRecord> record = new List<TestRecord>();  
while (csvread.Read()) {  
    TestRecord Record = csvread.GetRecord<TestRecord>();
    record.Add(Record);}