all groups > asp.net datagrid control > december 2005 >
You're in the

asp.net datagrid control

group:

Datagrid Paging Problem


Datagrid Paging Problem martinharvey via DotNetMonster.com
12/24/2005 7:35:24 AM
asp.net datagrid control:
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
Re: Datagrid Paging Problem Elton Wang
12/25/2005 10:19:15 AM
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
way to workaround is once you change record, set CurrentPageIndex = 0, first
page.

HTH


[quoted text, click to view]

Re: Datagrid Paging Problem martinharvey via DotNetMonster.com
12/28/2005 7:32:36 AM
[quoted text, click to view]

Thank you for your help

martin

--
AddThis Social Bookmark Button