Good day.
It is necessary to display 5 entries on the page with the ability to move to another page.
Asp.Net WebForms
Technology
I decided to use a GridView
for this and to fill in the LinqDataSource
data.
I create the grid myself
<asp:GridView ID="gvEmployees" runat="server" AllowPaging="True" PageSize="5" AllowSorting="True" DataSourceID="LinqDataSource1" EmptyDataText="Элементов нет" AutoGenerateColumns="False"> <Columns> <asp:BoundField SortExpression="Title" DataField="EmployeeId" HeaderText="ID" /> <asp:BoundField SortExpression="Title" DataField="EmployeeName" HeaderText="Name" /> <asp:BoundField SortExpression="Title" DataField="EmployeeSalary" HeaderText="Salary" /> </Columns> </asp:GridView> <asp:LinqDataSource ID="LinqDataSource1" runat="server" OnSelecting="LinqDataSource1_Selecting"></asp:LinqDataSource>
Fill it up like this:
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e) { e.Result = from p in _employees select new { EmployeeId = p.EmployeeId, EmployeeName = p.EmployeeName, EmployeeSalary = p.CalculateMonthlySalary() }; }
The problem is that when you move through the pages, the data is loaded by the new one and the data is added to GridViev
.
How to make paginated output of data?
Is this implementation correct?
Thank!