hello everyone,
i8 have a gridview with 2000 rows. i fill a page dynamically into a panel, but it shows only 10 rows. i cannot see the rest, in additional pages. how should i define or create new page (next page) for the rest of gridview's rows.
appreciate your respond with codes. kind regards
venus najadPosted Aug 24, 2024, 12:33 AM
mr Gupta
how should i fill a page in magtrix form?
i have used 2D-panel and i fill a table inside a loop and
but it doesnt show in matrix only in rows???!!!
when i use this.Controls.Add(form2); after the loop, i get error:
Control 'ctl02' of type 'LinkButton' must be placed inside a form tag with runat=server.
while is have defined HtmlForm form2 = new HtmlForm(); and i have dynamically linkbutton in table. even i have defined:
when i use form2.Controls.Add(panels[row, col]); instead of this.form2.Controls.Add(panels[row, col]); and add
this.Controls.Add(form2); after the loop, the page is empty???!!! why is that?
i appreciate your respond with codes, kind regards
venus najadPosted Aug 22, 2024, 7:19 PM
hello mr Aman Gupta
thanks for your respond, but it wasnt any button or linkbutton for next or previous page!??
if so i must redirect to next page!!!???
i have put pagesize=10000, for insurance....
thanks if you answer with codes...kind regards
Aman GuptaPosted Aug 22, 2024, 7:24 AM
Hi Venus,
To handle large datasets like your 2000 rows in a GridView, you can implement paging to display the data across multiple pages. Here’s how you can achieve this in C# ASP.NET WebForms:
Step 1: Enable Paging in the GridView
Enable paging directly on the GridView control by setting its
AllowPagingproperty totrueand defining thePageSize.Step 2: Bind Data to the GridView
In your code-behind, bind the data to the GridView. Make sure you only bind the data when the page is not being posted back (i.e., on the first load).
Step 3: Handle Page Index Changing Event
To navigate between pages, handle the
PageIndexChangingevent of the GridView.Step 4: (Optional) Customize Paging Appearance
If you want to customize the appearance of the paging controls (e.g., showing first, previous, next, and last buttons), you can do this in the GridView's
PagerSettings.Complete Example Code
Here’s how the complete implementation would look:
ASP.NET WebForm (ASPX):
Code-Behind (C#):
Conclusion
With the above code, you’ll have a GridView that displays 10 rows per page and allows users to navigate through the pages to view all 2000 rows. This approach makes your web application more user-friendly and efficient when dealing with large datasets.