ELELVEAFFIRTY
New Member
I start to learn ASP.NET.. and Datagrid.<BR>And i can't find a way to use OnItemCommand and OnPageIndexChanged at the same time.<BR>Everything is working fine until i try to changed to page 2.<BR><BR>did someone have a solution ?<BR>Thanks! <BR><BR>Here's my code with the error message when changing to page 2..<BR><BR>Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index<BR><BR>Source Error: <BR><BR><BR>Line 39: <BR>Line 40: Sub ArtDetails(sender as Object, e As DataGridCommandEventArgs)<BR>Line 41: Dim clecol as integer = Convert.ToInt32(e.Item.Cells(2).text)<BR>Line 42: dim mConn as New ODBCConnection()<BR>Line 43: mConn.connectionstring = "DSN=pacs"<BR> <BR><BR>Source File: c:inetpubwwwrootaspnetdataset.aspx Line: 41 <BR><BR><BR><BR>And now my code...<BR><BR><%@ Page Language="VB" Debug="true" %><BR><%@ Import Namespace="Microsoft.Data.Odbc" %><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="system.Web" %><BR><script runat="server"><BR><BR>Sub Page_Load(sender as object, e as eventargs)<BR> If Not Page.IsPostBack then<BR> Bdread()<BR> End If<BR>end sub<BR><BR>Sub Bdread()<BR> dim mConn as New ODBCConnection()<BR> mConn.connectionstring = "DSN=****"<BR> mConn.open()<BR> dim mAdap as New ODBCDataAdapter("Select * from PAC",mConn)<BR> Try<BR> dim mDs as New Dataset("pac")<BR> mAdap.Fill(mDs)<BR> ls.datasource=mDs<BR> ls.databind()<BR> Catch<BR> response.write ("Failed!")<BR> End Try<BR>end sub<BR><BR>Sub BindData(sortExpr as String)<BR> dim mConn as New ODBCConnection() <BR> mConn.connectionstring = "DSN=****"<BR> <BR> Dim mAdap as New ODBCDataAdapter("Select PAC WHERE" & sortExpr,mConn) <BR> mConn.Open()<BR> dim mDs as New Dataset("pac")<BR> mAdap.Fill(mDs)<BR> ls.DataSource = mDs<BR> ls.DataBind() <BR>End Sub<BR><BR>Sub ArtDetails(sender as Object, e As DataGridCommandEventArgs)<BR> Dim clecol as integer = Convert.ToInt32(e.Item.Cells(2).text)<BR> dim mConn as New ODBCConnection()<BR> mConn.connectionstring = "DSN=****"<BR> mConn.open()<BR> label1.text=clecol<BR> dim mAdap as New ODBCDataAdapter("Select * PAC WHERE (cle = " & clecol & ")",mConn)<BR> Try<BR> dim mDs as New Dataset("pac")<BR> mAdap.Fill(mDs)<BR> dt.datasource=mDs<BR> dt.databind()<BR> Catch<BR> response.write ("Failed!")<BR> End Try<BR>end sub<BR><BR>Sub change(sender as Object , e as DataGridPageChangedEventArgs)<BR> ls.CurrentPageIndex = e.NewPageIndex<BR> Bdread()<BR>End Sub<BR><BR>Sub Sortlist(sender as Object, e as DataGridSortCommandEventArgs)<BR> binddata(e.SortExpression)<BR>End Sub<BR><BR></script><BR><BR><html><BR><body><BR><BR><form runat="server"><BR><asp:label id="label1" runat="server" Font-Bold="True" /><BR><asp:label id="label2" runat="server" Font-Bold="True" /><BR><asp:datagrid id=dt runat="server" allowsorting="true" AutoGenerateColumns="False" Font-Name="Verdana" CellPadding="4" Font-Size="10pt"><BR> <headerstyle forecolor="yellow" backcolor="black"/><BR> <Columns><BR> <asp:BoundColumn HeaderText="Titre" DataField="titre"/><BR> <asp:BoundColumn HeaderText="Cle" DataField="cle"/><BR> <asp:BoundColumn HeaderText="Nom" DataField="nom"/><BR> </Columns><BR> <AlternatingItemStyle BackColor="lightgrey"/><BR></asp:datagrid><BR><BR><p></p><BR><BR><asp:datagrid id=ls allowsorting="true" onsortcommand="sortlist" runat="server" allowpaging="true" pagesize="30" AutoGenerateColumns="False" onitemcommand="artdetails" Font-Name="Verdana" CellPadding="4" Font-Size="10pt" OnPageIndexChanged="change"><BR> <headerstyle forecolor="yellow" backcolor="black"/><BR> <Columns><BR> <asp:ButtonColumn Text="Details" HeaderText="Details" ButtonType="PushButton"/><BR> <asp:BoundColumn DataField="titre" headertext="Titre de l'annonce" sortexpression="Titre"/><BR> <asp:BoundColumn DataField="cle" visible="false"/><BR> <asp:BoundColumn DataField="nom" visible="false"/><BR> </Columns><BR> <AlternatingItemStyle BackColor="lightgrey"/><BR></asp:datagrid><BR></form><BR><BR></body><BR></html><BR>