tbcmartinharvey Posted December 25, 2005 Posted December 25, 2005 This is probably a simple question but i would appreciate some help. I am trying to implement paging with a datagrid that also has a button that allows the user to insert selected information into a datatable thus: <asp:DataGrid id="dg" runat="server" ShowHeader="False" AutoGenerateColumns="False" Width="754px" CellPadding="10" HorizontalAlign="Center" OnItemCommand="AddProduct" DataKeyField="ProductID" OnItemCommand="AddProduct" OnPageIndexChanged="pager" AllowPaging="True" > This works ok if I leave out the paging or the on item Command but they wont work together. If i try to use them together i get the message "Out of range exception". Can anyone tell me where i am going wrong Many thanks Martin For reference the page code is: Sub Page_Load(sender As Object, e AS EventArgs) If Not Page.IsPostBack then dg.DataSource = Catalog.SP_GetInfo() dg.DataBind End If End Sub Sub pager(sender as Object, e As DatagridPageChangedEventArgs) dg.CurrentPageIndex = e.NewPageIndex dg.DataSource = Catalog.SP_GetInfo() dg.DataBind() End Sub Sub AddProduct(sender As Object, e As DataGridCommandEventArgs) ShoppingCart.AddProduct(dg.DataKeys(e.Item.ItemIndex)) End Sub Quote
bri189a Posted December 26, 2005 Posted December 26, 2005 For your error you need to get your datasource first in your pager sub routine: dg.DataSource = Catalog.SP_GetInfo() dg.CurrentPageIndex = e.NewPageIndex dg.DataBind() Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.