Normally during performing datagrid pagination, it's better to keep record
number of datagrid's data source. If you change record, it might causes
CurrentPageIndex to be referred to wrong one, out of range exception. One
"martinharvey via DotNetMonster.com" <u14945@uwe> wrote in message
news:594d6d0c9585f@uwe...
> 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
>
> --
> Message posted via DotNetMonster.com
>
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-datagrid/200512/1