简体   繁体   中英

How to manage Large amount of Data in GridView

I Have a table with 10000 records, so I want call only 15 Records at a single time using Stored procedure.

At the Next time call only next 15 Reocords and go On...

Please Help me out!!...If Possible Give Code With Example and Stored Procedure...Thank You!!!

Use paging in gridview as AllowPaging="true" then use OnPageIndexChanging Event and give us PageSize see below example

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
                OnPageIndexChanging="OnPageIndexChanging" PageSize="10">
                <Columns>
                    <asp:BoundField ItemStyle-Width="150px" DataField="Column_Name" HeaderText="Header Name" />
                    <asp:BoundField ItemStyle-Width="150px" DataField="Column_Name" HeaderText="Header Name" />
                    <asp:BoundField ItemStyle-Width="150px" DataField="Column_Name" HeaderText="Header Name" />
                </Columns>
            </asp:GridView>

Now bind the gridview with database on Page_Load Event

     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindGrid();
                }
            }

        private void BindGrid()
        {
            string conStr = @"Your connection string here";
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM Table_Name"))
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.Connection = con;
                        sda.SelectCommand = cmd;
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);
                            GridView1.DataSource = dt;
                            GridView1.DataBind();
                        }
                    }
                }
            }
        }

for pages use newPageIndex on OnPageIndexChanging event

    protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindGrid();
    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM