ASPX GridView isn’t show all the data bound to it?

I’m loading 4 items which right up to the .DataBind() call but it only shows 1 item on the Grid after loading.

Here’s some code:


<asp:GridView runat="server" ID="ItemsGrid" DataKeyNames="Id" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover" OnRowDataBound="ItemsGrid_RowDataBound" OnSelectedIndexChanging="ItemsGrid_SelectedIndexChanging" OnRowDeleting="ItemsGrid_RowDeleting" OnPageIndexChanging="ItemsGrid_PageIndexChanging" EmptyDataText="There are no items to display." PageSize="10" AllowPaging="false" PagerSettings-Position="TopAndBottom" PagerSettings-Visible="true" PagerSettings-Mode="NumericFirstLast" PagerSettings-FirstPageText="&lt; First" PagerSettings-LastPageText="Last &gt;" PagerStyle-CssClass="pagination-ys"> <Columns> <asp:CommandField ShowSelectButton="true" SelectText="<i class='glyphicon glyphicon-pencil'></i>" ItemStyle-Width="30" /> <asp:CommandField ShowDeleteButton="true" DeleteText="<i class='glyphicon glyphicon-trash'></i>" ItemStyle-Width="30" /> <asp:BoundField DataField="Name" HeaderText="Event" /> <asp:BoundField DataField="StartDate" HeaderText="Starts" DataFormatString="{0:yyyy/MM/dd}" /> <asp:BoundField DataField="EndDate" HeaderText="Ends" DataFormatString="{0:yyyy/MM/dd}" /> <asp:BoundField DataField="Venue" HeaderText="Venue" /> <asp:BoundField DataField="Address" HeaderText="Address" /> </Columns> </asp:GridView> 


private void LoadEvents(int pageNumber = 0) { var repo = new EventsRepository(); var items = repo.ListItems(pageNumber); ItemsGrid.DataSource = items; ItemsGrid.DataBind(); } 


public List<EventViewModel> ListItems(int pageNumber = 0) { var repo = new DataRepository<Event>(new ApplicationDbContext()); var items = BuildViewModel(repo.ListItems(pageNumber)); return items; } 


public class DataRepository<T> where T : BaseDataObject { private readonly DbContext _context; public DataRepository(DbContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); } public List<T> ListItems(int pageNumber = 0) { var items = _context.Set<T>().Where(x => !x.Deleted).OrderBy(x => x.Id).Skip(10 * pageNumber).ToList(); return items; } } 

I’m not seeing this problem on any other page. Every page further down the stack, eventually hits the DataRepository obviously but the repo for each page does essentially the same thing.

I don’t see any reason why this isn’t showing more than 1 record when the data source has more than 1 record in it.

Anything look messed up here?

submitted by /u/lcyduh
[link] [comments]

Leave a Reply