I'm just a poor beginner on ASP and C#. When running below two GridViews, just get in the default.aspx
page the Gridview1. Tried also defining DataSourceId in aspx code but without success. Looks like ASP only shows the first gridview found in the code ignoring the second one. Really appreciate your help!
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; }
}
This is the aspx part:
<%@ 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>
I have fixed the issue by replacing
IEnumerable<TestRecord> record = csvread.GetRecords<TestRecord>();
by:
List<TestRecord> record = new List<TestRecord>();
while (csvread.Read()) {
TestRecord Record = csvread.GetRecord<TestRecord>();
record.Add(Record);}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.