Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...