gridview paging in .net 2.0 and c# with oracle data base

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sahar Madahian
    New Member
    • May 2007
    • 16

    gridview paging in .net 2.0 and c# with oracle data base

    Hi!

    I have a girdview that use oracle database, the result is more than more page, how could I show the result in many page?

    I used AllowPaging="Tr ue", but the just the result of page one was right and for other pages I'v got this error:

    "Serverfeil i programmet /Totalsalg.
    GridView GridView1 started PageIndexChangi ng that is handeld."

    Please help me.

    <asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue" AllowSorting="F alse" GridLines="None "
    AutoGenerateCol umns="False" CellPadding="6" >
    <RowStyle BackColor="#FFF FFF" />
    <AlternatingRow Style BackColor="#CCC CCC" />
    <Columns>
    <asp:BoundFie ld DataField="QUAN TITY" HeaderText="Ant all" ReadOnly="True" AccessibleHeade rText="false" SortExpression= "QUANTITY" ItemStyle-HorizontalAlign ="Right" />
    <asp:BoundFie ld DataField="SUMN OK" DataFormatStrin g="{0:n0}" HtmlEncode="fal se" HeaderText="Pri s" ReadOnly="True" AccessibleHeade rText="false" SortExpression= "SUMNOK" ItemStyle-HorizontalAlign ="Right" />
    <asp:BoundFie ld DataField="RegD ate" HeaderText="Dat o" ReadOnly="True" AccessibleHeade rText="False" SortExpression= "RegDate" />
    </Columns>
    </asp:GridView>


    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (!Page.IsPostBa ck)
    {

    OracleConnectio n MyConnection;
    OracleCommand MyCommand;
    OracleDataAdapt er MyAdaptor;
    DataTable MyTable = new DataTable();

    MyConnection = new OracleConnectio n();
    MyConnection.Co nnectionString = ConfigurationMa nager.Connectio nStrings["TestDB"].ConnectionStri ng;


    MyCommand = new OracleCommand() ;
    MyCommand.Comma ndText = "Select sum(o.quantity) as Quantity, SUM(o.quantity* s.price) as SumNOK, SUBSTR(o.regdat e,7,4)||'-'||SUBSTR(o.reg date,1,2)||'-'||SUBSTR(o.reg date,4,2) as RegDate FROM shamrock.cat_or der o, shamrock.cat_sa lesproduct s WHERE o.salesproductI d=s.salesproduc tnum GROUP BY SUBSTR(o.regdat e,7,4)||'-'||SUBSTR(o.reg date,1,2)||'-'||SUBSTR(o.reg date,4,2)";
    MyCommand.Comma ndType = CommandType.Tex t;
    MyCommand.Conne ction = MyConnection;


    MyAdaptor = new OracleDataAdapt er();
    MyAdaptor.Selec tCommand = MyCommand;
    MyAdaptor.Fill( MyTable);

    GridView1.DataS ource = new DataView(MyTabl e, String.Empty, "REGDATE DESC", DataViewRowStat e.CurrentRows);
    GridView1.DataB ind();

    MyAdaptor.Dispo se();
    MyCommand.Dispo se();
    MyConnection.Di spose();

    }
    }
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    Your error message is not clear. Are you getting the error when you are changing the Page Index?

    Originally posted by Sahar Madahian
    Hi!

    I have a girdview that use oracle database, the result is more than more page, how could I show the result in many page?

    I used AllowPaging="Tr ue", but the just the result of page one was right and for other pages I'v got this error:

    "Serverfeil i programmet /Totalsalg.
    GridView GridView1 started PageIndexChangi ng that is handeld."

    Please help me.

    <asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue" AllowSorting="F alse" GridLines="None "
    AutoGenerateCol umns="False" CellPadding="6" >
    <RowStyle BackColor="#FFF FFF" />
    <AlternatingRow Style BackColor="#CCC CCC" />
    <Columns>
    <asp:BoundFie ld DataField="QUAN TITY" HeaderText="Ant all" ReadOnly="True" AccessibleHeade rText="false" SortExpression= "QUANTITY" ItemStyle-HorizontalAlign ="Right" />
    <asp:BoundFie ld DataField="SUMN OK" DataFormatStrin g="{0:n0}" HtmlEncode="fal se" HeaderText="Pri s" ReadOnly="True" AccessibleHeade rText="false" SortExpression= "SUMNOK" ItemStyle-HorizontalAlign ="Right" />
    <asp:BoundFie ld DataField="RegD ate" HeaderText="Dat o" ReadOnly="True" AccessibleHeade rText="False" SortExpression= "RegDate" />
    </Columns>
    </asp:GridView>


    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (!Page.IsPostBa ck)
    {

    OracleConnectio n MyConnection;
    OracleCommand MyCommand;
    OracleDataAdapt er MyAdaptor;
    DataTable MyTable = new DataTable();

    MyConnection = new OracleConnectio n();
    MyConnection.Co nnectionString = ConfigurationMa nager.Connectio nStrings["TestDB"].ConnectionStri ng;


    MyCommand = new OracleCommand() ;
    MyCommand.Comma ndText = "Select sum(o.quantity) as Quantity, SUM(o.quantity* s.price) as SumNOK, SUBSTR(o.regdat e,7,4)||'-'||SUBSTR(o.reg date,1,2)||'-'||SUBSTR(o.reg date,4,2) as RegDate FROM shamrock.cat_or der o, shamrock.cat_sa lesproduct s WHERE o.salesproductI d=s.salesproduc tnum GROUP BY SUBSTR(o.regdat e,7,4)||'-'||SUBSTR(o.reg date,1,2)||'-'||SUBSTR(o.reg date,4,2)";
    MyCommand.Comma ndType = CommandType.Tex t;
    MyCommand.Conne ction = MyConnection;


    MyAdaptor = new OracleDataAdapt er();
    MyAdaptor.Selec tCommand = MyCommand;
    MyAdaptor.Fill( MyTable);

    GridView1.DataS ource = new DataView(MyTabl e, String.Empty, "REGDATE DESC", DataViewRowStat e.CurrentRows);
    GridView1.DataB ind();

    MyAdaptor.Dispo se();
    MyCommand.Dispo se();
    MyConnection.Di spose();

    }
    }

    Comment

    • Sahar Madahian
      New Member
      • May 2007
      • 16

      #3
      Yes, when I want to see other pages,I'v got error.

      Comment

      • Sahar Madahian
        New Member
        • May 2007
        • 16

        #4
        Yes, when I want to see other pages,I'v got error.

        Comment

        • Vidhura
          New Member
          • May 2007
          • 99

          #5
          Hope the following helps

          1.Add PageIndexChangi ng event
          <asp:GridView ID="GridView1" runat="server" Height="539px" AllowPaging="Tr ue"
          Width="628px" OnPageIndexChan ging="GridView1 _PageIndexChang ing">
          </asp:GridView>

          2.Assign newpageindex to the gridview in the event
          protected void GridView1_PageI ndexChanging(ob ject sender, GridViewPageEve ntArgs e)
          {
          GridView1.PageI ndex = e.NewPageIndex;
          GridView1.DataB ind();

          }

          Comment

          • Sahar Madahian
            New Member
            • May 2007
            • 16

            #6
            I tried it and I didn't get the error again, but it works just for the first page and when I change the page, other page is empty!

            Comment

            • Sahar Madahian
              New Member
              • May 2007
              • 16

              #7
              Hi. please help me about paging.

              Comment

              • Vidhura
                New Member
                • May 2007
                • 99

                #8
                Originally posted by Sahar Madahian
                Hi. please help me about paging.
                Hi ,the problem is with Ispostback

                Remove the if condition and check
                if (!Page.IsPostBa ck)
                {}

                Comment

                Working...