我正在尝试用来自数据库视图的数据填充 Gridview。我不能使用 linq,因为视图有 200+k 行我必须显示。这是我的代码:
public partial class _Default : System.Web.UI.Page
{
private string mobileGateway = "MobileGateway";
private List<string> addressReport = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
GetReport(addressReport);
}
public void GetReport(List<string> adr)
{
string connecntionString = ConfigurationManager.ConnectionStrings[mobileGateway].ConnectionString;
using (SqlConnection connection = new SqlConnection(connecntionString))
{
try
{
connection.Open();
string sqlCmd = "SELECT * from dbo.BarcodeWithLocation";
using (SqlCommand command = new SqlCommand(sqlCmd, connection))
{
command.CommandType = System.Data.CommandType.Text;
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
adr.Add("" + reader[0]);
adr.Add("" + reader[1]);
adr.Add("" + reader[2]);
adr.Add("" + reader[3]);
adr.Add("" + reader[4]);
adr.Add("" + reader[5]);
adr.Add("" + reader[6]);
adr.Add("" + reader[7]);
adr.Add("" + reader[8]);
adr.Add("" + reader[9]);
adr.Add("" + reader[10]);
}
Grid.DataSource = adr;
Grid.DataBind();
}
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR!!!!: " + ex.Message);
}
}
}
}
}
asp代码:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="AddressReporting._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:GridView ID="Grid" runat="server" AllowPaging="True"
AutoGenerateColumns="False">
</asp:GridView>
</asp:Content>
我得到一个完全没有gridview 的空白页。我究竟做错了什么 ?