Adding sorting, paging, or editing features to a DataGrid usually involves a few simple steps. For example, to sort the contents of a DataGrid, we set the DataGrid's AllowSorting property to True and provide an event handler for the DataGrid's SortCommand event. To include pagination support, we set the DataGrid's AllowPaging property to True and provide an event handler for the DataGrid's PageIndexChanged event. Adding both sorting and pagination abilities to one DataGrid is, unfortunately, not as simple as just setting the AllowSorting and AllowPaging properties to True and writing the two needed event handlers. Instead, a bit more care needs to be taken. For example, as we saw in Chapter 7, "Sorting the DataGrid's Data," typically when sorting, we include a modified version of the BindData() subroutine BindData(sortExpression ) that takes a string input parameter that specifies what column of the DataGrid to sort the contents on. However, with the pagination examples, we used the parameter-less version of BindData(). This is one example where we must take care when providing multiple features for a single DataGrid. In this chapter we will look first at creating a DataGrid that supports both sorting and pagination. After we have accomplished this, we'll examine how to also allow the data to be modified (edited and deleted). |