简体   繁体   English

超过1000条记录的GridView问题

[英]GridView issue with more than 1000 records

I'm having some performance issues when I return a record set with more than 1,000 records. 当我返回一个包含1000多个记录的记录集时,我遇到了一些性能问题。

Sometimes the records are in upwards of 2,100 but can be as low as 10. 有时记录超过2,100,但可能低至10。

I have some bulk actions that I take on all the records by selecting them. 通过选择所有记录,我可以执行一些批量操作。

However, when the number is low, the Gridview is fine. 但是,当数量较少时,Gridview很好。 When the record count is greater than 500 I see performance issues on the page. 当记录数大于500时,我会在页面上看到性能问题。

What I want to happen is: if there are more than 500 records, DO NOT DISPLAY THE GRID , instead show a download button that exports to CSV or do other control things on the page. 我要发生的事情是:如果有500条以上的记录,请不要显示网格 ,而是在页面上显示一个导出为CSV或其他控件的下载按钮。

My issue: Even if i tell it not to display the grid and instead display a message and a button, the performance is still slow. 我的问题:即使我告诉它不显示网格,而是显示一条消息和一个按钮,性能仍然很慢。

Below is my C# code for populating the GridView. 下面是我的用于填充GridView的C#代码。 Some stuff has been removed that are unimportant and to help with readability. 删除了一些不重要的东西,以帮助提高可读性。

How can I adjust my C# code for better performance? 如何调整C#代码以获得更好的性能?

SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectString"].ToString());
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SomeProcedure";
cmd.Parameters.Add(SearchParam);

try {
    DataTable GridData = new DataTable();

    conn.Open();
    using(SqlDataAdapter Sqlda = new SqlDataAdapter(cmd)) {
        Sqlda.Fill(GridData);
    }

    if (GridData.Rows.Count == 0) {
        lblSearchMsg.Text = "No Fee Records are in the Queue at this time.";
    } else {


        if (GridData.Rows.Count > 500) {
            lblSearchMsg.Text = "More than " + gridLimit.ToString() + " records returned.";
            //Show the download button

        } else {
            //Persist the table in the Session object. (for sorting)
            Session["GridData"] = GridData;

            lblRowCount.Text = "Count: " + GridData.Rows.Count.ToString();

            myGridView.DataSource = GridData;
            myGridView.DataBind();
            myGridView.Visible = true;
        }
    }

} catch (Exception ex) {
    //Do the error stuff
} finally {
    if (conn != null) {
        conn.Close();
    }
}
  1. Create a separate procedure that returns only the row count. 创建一个单独的过程,该过程仅返回行数。
    Check that value not the row count of a fully retrieved data set then retrieve the full data set as needed. 检查值而不是完全检索的数据集的行数,然后根据需要检索完整的数据集。

  2. Keep in mind you can use the same connection to do both retrievals, no need to close the connection between calls. 请记住,您可以使用相同的连接进行两次检索,而无需关闭调用之间的连接。

  3. if you determine you need to fill a gridview and there is no need to edit the data you can read into the DataTable without the use of an adapter. 如果确定需要填充gridview且无需编辑数据,则无需使用适配器就可以读取到DataTable中。 Here is the basic idea modify with using statements or try/catch as you prefer: 这是您可以根据需要using语句或try / catch进行修改的基本思想:


    conn = new SqlConnection(connString);
    string query = "SELECT * FROM ....";
    SqlCommand cmd = new SqlCommand(query, conn);
    conn.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    DataTable dt = new DataTable();
    dt.Load(dr);
    GridView1.DataSource = dt;
    GridView1.DataBind();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将超过1000条记录传递给kendo gridview - Not able to pass more than 1000 records to kendo gridview 当多个客户端在同一表中插入超过1000条记录的数组时,数据库锁定问题 - Database locked issue while Inserting in same table the Array of more than 1000 records by multiple client 一次性在SQL Server 2008中插入1000条以上的记录 - Insert more than 1000 records in SQL Server 2008 in one go 我可以从 DirectorySearcher 中获取 1000 多条记录吗? - Can I get more than 1000 records from a DirectorySearcher? 我可以从PrincipalSearcher中获得1000条以上的记录吗? - Can I get more than 1000 records from a PrincipalSearcher? GridView显示多于1000行 - GridView display more then 1000 rows 如何在C#中列出来自Google Drive API V3的1000多条记录 - How to list of more than 1000 records from Google Drive API V3 in C# 查询结果超过1000条记录时,Dapper抛出System.Data.SqlClient.SqlException - System.Data.SqlClient.SqlException Thrown by Dapper When Query Result Has More Than 1000 Records 将pdf页面转换为1000张以上的图像 - Convert pdf pages to images more than 1000 将超过 1000 行写入 Google 表格 - Writing more than 1000 rows into Google Sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM