DataGrid Paging

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexandre Jaquet

    DataGrid Paging

    Hi I really can't figure out what's wrong with my code

    <asp:datagrid id="DataGrid1" runat="server"
    AllowPaging="Tr ue"
    AllowSorting="T rue"
    AutoGenerateCol umns="True"
    OnPageIndexChan ged="ChangeInde x">
    <PagerStyle Mode="NumericPa ges"></PagerStyle>
    ....

    private void Page_Load(objec t sender, System.EventArg s e)
    {
    if (!Page.IsPostBa ck)
    {
    this.sqlConnect ion1 = new SqlConnection (DBConstant.con nectionDB);
    this.sqlConnect ion1.Open ();
    HttpCookie cookie = Request.Cookies["hopitalID"];
    strCookieValue = cookie.Value.To String(); fillData ();
    DataGrid1.Curre ntPageIndex = 1;
    }
    }

    private void fillData ()
    {
    string sql = "SELECT DISTINCT FACTURE.ID_NR_F ACTURE, " +
    "ANALYSE.ID_ANA LYSE, FACTURE.DATE_FA CTURE " +
    "AS DATE_FACTURE, PATIENT.PRENOM_ PATIENT, " +
    "PATIENT.NOM_PA TIENT ,FACTURE.FACTUR E, " +
    "FACTURE.ACQUIT TE FROM PATIENT, LABORATOIRE, " +
    "ANALYSE, FACTURE WHERE ANALYSE.ID_ANAL YSE = " +
    "FACTURE.ID_ANA LYSE AND ANALYSE.ID_PATI ENT = " +
    "PATIENT.ID_PAT IENT AND ANALYSE.LABO_ID = " +
    "LABORATOIRE.ID _LABORATOIRE AND " +
    "LABORATOIRE.DE SIGNATION_LABOR ATOIRE = '" +
    strCookieValue + "'" ;
    DataSet ds = new DataSet ();
    SqlDataAdapter adapter = new SqlDataAdapter (sql, this.sqlConnect ion1);
    adapter.Fill (ds);
    this.DataGrid1. DataSource = ds;
    this.DataGrid1. DataBind();
    }

    protected void ChangeIndex(obj ect source,
    System.Web.UI.W ebControls.Data GridPageChanged EventArgs e)
    {
    DataGrid1.Curre ntPageIndex = e.NewPageIndex;
    fillData ();
    }

    really thanks in advance
  • ranganh

    #2
    RE: DataGrid Paging

    Dear Alexandre,

    Change your Paging method's access level to public, as follows:-

    public void ChangeIndex(obj ect source,
    System.Web.UI.W ebControls.Data GridPageChanged EventArgs e)
    {
    DataGrid1.Curre ntPageIndex = e.NewPageIndex;
    fillData ();
    }

    That should solve your problem.

    Thanks.





    "Alexandre Jaquet" wrote:
    [color=blue]
    > Hi I really can't figure out what's wrong with my code
    >
    > <asp:datagrid id="DataGrid1" runat="server"
    > AllowPaging="Tr ue"
    > AllowSorting="T rue"
    > AutoGenerateCol umns="True"
    > OnPageIndexChan ged="ChangeInde x">
    > <PagerStyle Mode="NumericPa ges"></PagerStyle>
    > ...
    >
    > private void Page_Load(objec t sender, System.EventArg s e)
    > {
    > if (!Page.IsPostBa ck)
    > {
    > this.sqlConnect ion1 = new SqlConnection (DBConstant.con nectionDB);
    > this.sqlConnect ion1.Open ();
    > HttpCookie cookie = Request.Cookies["hopitalID"];
    > strCookieValue = cookie.Value.To String(); fillData ();
    > DataGrid1.Curre ntPageIndex = 1;
    > }
    > }
    >
    > private void fillData ()
    > {
    > string sql = "SELECT DISTINCT FACTURE.ID_NR_F ACTURE, " +
    > "ANALYSE.ID_ANA LYSE, FACTURE.DATE_FA CTURE " +
    > "AS DATE_FACTURE, PATIENT.PRENOM_ PATIENT, " +
    > "PATIENT.NOM_PA TIENT ,FACTURE.FACTUR E, " +
    > "FACTURE.ACQUIT TE FROM PATIENT, LABORATOIRE, " +
    > "ANALYSE, FACTURE WHERE ANALYSE.ID_ANAL YSE = " +
    > "FACTURE.ID_ANA LYSE AND ANALYSE.ID_PATI ENT = " +
    > "PATIENT.ID_PAT IENT AND ANALYSE.LABO_ID = " +
    > "LABORATOIRE.ID _LABORATOIRE AND " +
    > "LABORATOIRE.DE SIGNATION_LABOR ATOIRE = '" +
    > strCookieValue + "'" ;
    > DataSet ds = new DataSet ();
    > SqlDataAdapter adapter = new SqlDataAdapter (sql, this.sqlConnect ion1);
    > adapter.Fill (ds);
    > this.DataGrid1. DataSource = ds;
    > this.DataGrid1. DataBind();
    > }
    >
    > protected void ChangeIndex(obj ect source,
    > System.Web.UI.W ebControls.Data GridPageChanged EventArgs e)
    > {
    > DataGrid1.Curre ntPageIndex = e.NewPageIndex;
    > fillData ();
    > }
    >
    > really thanks in advance[/color]

    Comment

    • Alexandre Jaquet

      #3
      RE: DataGrid Paging

      Thanks for your response but it's still doesn't work, I just open a book
      about asp.net and they purpose another solution but still doesn't work ...

      If someone have a working sample it's would be great

      "ranganh" wrote:
      [color=blue]
      > Dear Alexandre,
      >
      > Change your Paging method's access level to public, as follows:-
      >
      > public void ChangeIndex(obj ect source,
      > System.Web.UI.W ebControls.Data GridPageChanged EventArgs e)
      > {
      > DataGrid1.Curre ntPageIndex = e.NewPageIndex;
      > fillData ();
      > }
      >
      > That should solve your problem.
      >
      > Thanks.
      >
      >
      >
      >
      >
      > "Alexandre Jaquet" wrote:
      >[color=green]
      > > Hi I really can't figure out what's wrong with my code
      > >
      > > <asp:datagrid id="DataGrid1" runat="server"
      > > AllowPaging="Tr ue"
      > > AllowSorting="T rue"
      > > AutoGenerateCol umns="True"
      > > OnPageIndexChan ged="ChangeInde x">
      > > <PagerStyle Mode="NumericPa ges"></PagerStyle>
      > > ...
      > >
      > > private void Page_Load(objec t sender, System.EventArg s e)
      > > {
      > > if (!Page.IsPostBa ck)
      > > {
      > > this.sqlConnect ion1 = new SqlConnection (DBConstant.con nectionDB);
      > > this.sqlConnect ion1.Open ();
      > > HttpCookie cookie = Request.Cookies["hopitalID"];
      > > strCookieValue = cookie.Value.To String(); fillData ();
      > > DataGrid1.Curre ntPageIndex = 1;
      > > }
      > > }
      > >
      > > private void fillData ()
      > > {
      > > string sql = "SELECT DISTINCT FACTURE.ID_NR_F ACTURE, " +
      > > "ANALYSE.ID_ANA LYSE, FACTURE.DATE_FA CTURE " +
      > > "AS DATE_FACTURE, PATIENT.PRENOM_ PATIENT, " +
      > > "PATIENT.NOM_PA TIENT ,FACTURE.FACTUR E, " +
      > > "FACTURE.ACQUIT TE FROM PATIENT, LABORATOIRE, " +
      > > "ANALYSE, FACTURE WHERE ANALYSE.ID_ANAL YSE = " +
      > > "FACTURE.ID_ANA LYSE AND ANALYSE.ID_PATI ENT = " +
      > > "PATIENT.ID_PAT IENT AND ANALYSE.LABO_ID = " +
      > > "LABORATOIRE.ID _LABORATOIRE AND " +
      > > "LABORATOIRE.DE SIGNATION_LABOR ATOIRE = '" +
      > > strCookieValue + "'" ;
      > > DataSet ds = new DataSet ();
      > > SqlDataAdapter adapter = new SqlDataAdapter (sql, this.sqlConnect ion1);
      > > adapter.Fill (ds);
      > > this.DataGrid1. DataSource = ds;
      > > this.DataGrid1. DataBind();
      > > }
      > >
      > > protected void ChangeIndex(obj ect source,
      > > System.Web.UI.W ebControls.Data GridPageChanged EventArgs e)
      > > {
      > > DataGrid1.Curre ntPageIndex = e.NewPageIndex;
      > > fillData ();
      > > }
      > >
      > > really thanks in advance[/color][/color]

      Comment

      Working...