Re: datagrid trouble

Discussion in 'ASP .Net' started by Juan Romero, Aug 26, 2004.

  1. Juan Romero

    Juan Romero Guest

    This is because you must set the page number manually and rebind the grid
    datasource on the PageIndexChanged Event:

    Private Sub dgClients_PageIndexChanged(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
    dgClients.PageIndexChanged
    dgClients.CurrentPageIndex = e.NewPageIndex
    dgClients.DataSource = CreateDataSource()
    dgClients.DataBind()
    End Sub

    Good luck!

    "Alexandre Jaquet" <> wrote in
    message news:D...
    > Hi I can't figure why I get this error when I click on next button
    >
    > Value CurrentPageIndex invalid, She should be >= 0 and < PageCount
    >
    > the code :
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (!Page.IsPostBack)
    > {
    > HttpCookie cookie = Request.Cookies["hopitalID"];
    > strCookieValue = cookie.Value.ToString();
    > BindGrid();
    > }
    > }
    >
    > private DataSet GetData()
    > {
    > String SQLStatement="SELECT DISTINCT FACTURE.ID_NR_FACTURE,
    > ANALYSE.ID_ANALYSE, FACTURE.DATE_FACTURE AS DATE_FACTURE,
    > PATIENT.PRENOM_PATIENT, PATIENT.NOM_PATIENT ,FACTURE.FACTURE,
    > FACTURE.ACQUITTE FROM PATIENT, LABORATOIRE, ANALYSE, FACTURE WHERE
    > ANALYSE.ID_ANALYSE = FACTURE.ID_ANALYSE AND ANALYSE.ID_PATIENT =
    > PATIENT.ID_PATIENT AND ANALYSE.LABO_ID = LABORATOIRE.ID_LABORATOIRE AND
    > LABORATOIRE.DESIGNATION_LABORATOIRE = '" + strCookieValue + "'";
    > SqlConnection myConnection= new SqlConnection(DBConstant.connectionDB);
    > SqlDataAdapter myCommand = new SqlDataAdapter(SQLStatement,myConnection);
    > DataSet myDataSet;
    > myCommand.SelectCommand.CommandType=CommandType.Text;
    > myDataSet = new DataSet();
    > myCommand.Fill(myDataSet, "FACTURE");
    > myCommand.Fill(myDataSet, "ANALYSE");
    > myCommand.Fill(myDataSet, "PATIENT");
    > return myDataSet;
    > }
    >
    > protected void BindGrid()
    > {
    > MyDataGrid.DataSource=GetData().Tables["FACTURE"].DefaultView;
    > MyDataGrid.DataSource=GetData().Tables["ANALYSE"].DefaultView;
    > MyDataGrid.DataSource=GetData().Tables["PATIENT"].DefaultView;
    > MyDataGrid.DataBind();
    > }
    >
    > public void MyDataGrid_PageIndexChanged(object source,
    > System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    > {
    > MyDataGrid.CurrentPageIndex=e.NewPageIndex;
    > BindGrid();
    > }
    >
    > and the asp.net code :
    >
    > <asp:datagrid id="MyDataGrid" runat="server"
    > AllowPaging="True"
    > PageSize="25"
    > PagerStyle-Mode="NextPrev"
    > PagerStyle-NextPageText="Next"
    > PagerStyle-PrevPageText="Previous"
    > PagerStyle-HorizontalAlign="Center"
    > PagerStyle-Position="TopAndBottom"
    > AutoGenerateColumns="True">
    > <SelectedItemStyle BackColor="Silver"></SelectedItemStyle>
    > <ItemStyle BackColor="White"></ItemStyle>
    > <HeaderStyle ForeColor="White" BackColor="#404040"></HeaderStyle>
    > <PagerStyle NextPageText="Next"
    > PrevPageText="Previous"
    > HorizontalAlign="Right"
    > ForeColor="Black"
    > Position="TopAndBottom"
    > BackColor="#C6C3C6"></PagerStyle>
    > </asp:datagrid>
    >
    >
     
    Juan Romero, Aug 26, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernt Fischer
    Replies:
    2
    Views:
    2,217
    Guogang
    Aug 28, 2003
  2. Hypo
    Replies:
    6
    Views:
    460
  3. Priya via .NET 247

    DataGrid trouble please help

    Priya via .NET 247, Aug 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    392
    Rick Spiewak
    Aug 11, 2004
  4. =?Utf-8?B?Y3dicDE3?=
    Replies:
    0
    Views:
    851
    =?Utf-8?B?Y3dicDE3?=
    Jul 23, 2005
  5. Andreas Klemt
    Replies:
    0
    Views:
    332
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page