tbcmartinharvey
Newcomer
- Joined
- Oct 7, 2005
- Messages
- 10
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:
<aspataGrid 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
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:
<aspataGrid 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