Wednesday, December 5, 2007

CodeSnip: Pivot Tables with ADO.NET and Display in a DataGrid Paged Horizontally: ASP Alliance

CodeSnip: Pivot Tables with ADO.NET and Display in a DataGrid Paged Horizontally: ASP Alliance: "Create the DataGrid [Download Code] The client wants to navigate thru the DataGrid Products horizontally and anchor the first column containing the Feature descriptions. We could implement horizontal scrolling using a DIV tag, but anchoring the first column becomes more problematic. Since our client wants to Page thru the Products, we can simply bind the appropriate columns to the DataGrid based on the DataGrids's current PageIndex. Since the DataGrid doesn't really support this type of paging, we'll implement our own Page navigation buttons, and maintain the current PageIndex in the ViewState. In the code snippets below, assume there is a 'Previous Page' button named prevBtn, and a 'Next Page' button named nextBtn. There is also a property named PageIndex that maintains the currently selected page index and is set when the previous and next buttons are clicked. When the page loads the first time, the PageIndex is set to zero and the BindHorzGrrd method is called. In subsequent PostBacks, the nextBtn and prevBtn modify the current PageIndex and then call the BindHorzGrid method. The first part of the BindHorzGrid method simply sets up some values that we'll need to decide which columns should be displayed for the current PageIndex. We also enable/disable"