Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. ASP.NET Gridview DataBound event retaining previous value

ASP.NET Gridview DataBound event retaining previous value

Scheduled Pinned Locked Moved ASP.NET
csharpcssasp-nethelp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Inderjeet Kaur
    wrote on last edited by
    #1

    I have a Grid view using ObjectDataSource. I add the values of a column and display it in a label in DataBound event. when i move to next page the value in label should change but its showing the values of first page only. Any help will be appreciated! Thanks in advance

    Inderjeet Kaur Sr. Software Engg

    A 1 Reply Last reply
    0
    • I Inderjeet Kaur

      I have a Grid view using ObjectDataSource. I add the values of a column and display it in a label in DataBound event. when i move to next page the value in label should change but its showing the values of first page only. Any help will be appreciated! Thanks in advance

      Inderjeet Kaur Sr. Software Engg

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      I think you haven't considered the page number while assigning value in row data bound so that you are asssigning value to label from the same object.Can you check that? :-D

      Arun Jacob http://codepronet.blogspot.com/

      I 1 Reply Last reply
      0
      • A Arun Jacob

        I think you haven't considered the page number while assigning value in row data bound so that you are asssigning value to label from the same object.Can you check that? :-D

        Arun Jacob http://codepronet.blogspot.com/

        I Offline
        I Offline
        Inderjeet Kaur
        wrote on last edited by
        #3

        When i click on Next Page, GridView RowDataBound event and Databound event will be called up. Label is getting right value but when it displays, it displays the previous value. Dono know howz it happening.

        Inderjeet Kaur Sr. Software Engg

        I 1 Reply Last reply
        0
        • I Inderjeet Kaur

          When i click on Next Page, GridView RowDataBound event and Databound event will be called up. Label is getting right value but when it displays, it displays the previous value. Dono know howz it happening.

          Inderjeet Kaur Sr. Software Engg

          I Offline
          I Offline
          Ibrahim Bello
          wrote on last edited by
          #4

          You have to post your code for us to know...

          I 1 Reply Last reply
          0
          • I Ibrahim Bello

            You have to post your code for us to know...

            I Offline
            I Offline
            Inderjeet Kaur
            wrote on last edited by
            #5

            protected void objCardFeesReport_Selected(object sender, ObjectDataSourceStatusEventArgs e) { try { if (e.Exception != null) { e.ExceptionHandled = true; } Int32 totalSearchRows = 0; if (e.ReturnValue.GetType() == typeof(System.Int32)) totalSearchRows = (Int32)e.ReturnValue; lblSummary.Text = "Total Records Found :" + " " + Convert.ToString(totalSearchRows); if (e.ReturnValue.GetType() == typeof(System.Data.DataSet)) { DataSet ds = (DataSet)e.ReturnValue; if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { String feeID = ds.Tables[0].Rows[i]["TRANTYPEID"].ToString(); Decimal feeAmount = Convert.ToDecimal(ds.Tables[0].Rows[i]["TRANSACTIONAMOUNT"]); if (feeID == "7") { totNewCardFee = totNewCardFee + feeAmount; } else if (feeID == "8") { totAdditionalFee = totAdditionalFee + feeAmount; } else if (feeID == "163") { totTxnFee = totTxnFee + feeAmount; } else if (feeID == "21") { totActFee = totActFee + feeAmount; } else if (feeID == "165") { totAnnualFee = totAnnualFee + feeAmount; } else if (feeID == "12") { totAuthFee = totAuthFee + feeAmount; } else if (feeID == "25") { totInactFee = totInactFee + feeAmount; } else if (feeID == "24") { totCardShipFee = totCardShipFee + feeAmoun

            I 1 Reply Last reply
            0
            • I Inderjeet Kaur

              protected void objCardFeesReport_Selected(object sender, ObjectDataSourceStatusEventArgs e) { try { if (e.Exception != null) { e.ExceptionHandled = true; } Int32 totalSearchRows = 0; if (e.ReturnValue.GetType() == typeof(System.Int32)) totalSearchRows = (Int32)e.ReturnValue; lblSummary.Text = "Total Records Found :" + " " + Convert.ToString(totalSearchRows); if (e.ReturnValue.GetType() == typeof(System.Data.DataSet)) { DataSet ds = (DataSet)e.ReturnValue; if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { String feeID = ds.Tables[0].Rows[i]["TRANTYPEID"].ToString(); Decimal feeAmount = Convert.ToDecimal(ds.Tables[0].Rows[i]["TRANSACTIONAMOUNT"]); if (feeID == "7") { totNewCardFee = totNewCardFee + feeAmount; } else if (feeID == "8") { totAdditionalFee = totAdditionalFee + feeAmount; } else if (feeID == "163") { totTxnFee = totTxnFee + feeAmount; } else if (feeID == "21") { totActFee = totActFee + feeAmount; } else if (feeID == "165") { totAnnualFee = totAnnualFee + feeAmount; } else if (feeID == "12") { totAuthFee = totAuthFee + feeAmount; } else if (feeID == "25") { totInactFee = totInactFee + feeAmount; } else if (feeID == "24") { totCardShipFee = totCardShipFee + feeAmoun

              I Offline
              I Offline
              Ibrahim Bello
              wrote on last edited by
              #6

              Try calling gvCardFeesRReport.DataBind() after setting the Page Index property of the gridview in your RowCommand event handler. Do like this: gvCardFeesRReport.PageIndex = 0; gvCardFeesRReport.DataBind(); Cheers!

              I 1 Reply Last reply
              0
              • I Ibrahim Bello

                Try calling gvCardFeesRReport.DataBind() after setting the Page Index property of the gridview in your RowCommand event handler. Do like this: gvCardFeesRReport.PageIndex = 0; gvCardFeesRReport.DataBind(); Cheers!

                I Offline
                I Offline
                Inderjeet Kaur
                wrote on last edited by
                #7

                No it didn't work. i give u the code of my gridview also <asp:UpdatePanel ID="pnlBG" runat="server"> <ContentTemplate> <asp:ObjectDataSource ID="objCardFeesReport" runat="server" TypeName="BLL.ReportBLL" SortParameterName="sortExpression" EnablePaging="true" SelectCountMethod="GetReportsRecCount" SelectMethod="GetCardFeesReport" OnSelected="objCardFeesReport_Selected"> <SelectParameters> <asp:Parameter Name="sortExpression" Type="String" /> <asp:Parameter Name="filteredBy" Type="String" /> <asp:Parameter Name="startRowIndex" DefaultValue="0" Type="Int32" /> <asp:Parameter Name="maximumRows" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> <asp:GridView ID="gvCardFeesRReport" runat="server" PageSize="10" AllowSorting="true" AllowPaging="true" AutoGenerateColumns="false" CellPadding="5" CellSpacing="0" Width="100%" DataSourceID="objCardFeesReport" CssClass="GridMain" OnPageIndexChanging="gvCardFeesRReport_PageIndexChanging" OnSorting="gvCardFeesRReport_Sorting" OnRowCommand="gvCardFeesRReport_RowCommand" > <HeaderStyle CssClass="HeaderRow" /> <RowStyle CssClass="NormalRow" /> <AlternatingRowStyle CssClass="AlternateRow" /> <PagerStyle CssClass="PagingRow" HorizontalAlign="Right" Height="20px" /> <SelectedRowStyle CssClass="HighlightedRow" /> <EmptyDataRowStyle CssClass="NoRecords" /> <EmptyDataTemplate> <asp:Label ID="lblNoRecords" Text="Your search did not yield any result." runat="server"> </asp:Label> <p> Suggestions:</p> <li>Try different Filter.</li> <li>There may be no records in the system.</li> </EmptyDataTemplate> <Columns> <asp:BoundField HeaderStyle-CssClass="gridViewHeader" DataField="AccountNumber" SortExpressio

                I 1 Reply Last reply
                0
                • I Inderjeet Kaur

                  No it didn't work. i give u the code of my gridview also <asp:UpdatePanel ID="pnlBG" runat="server"> <ContentTemplate> <asp:ObjectDataSource ID="objCardFeesReport" runat="server" TypeName="BLL.ReportBLL" SortParameterName="sortExpression" EnablePaging="true" SelectCountMethod="GetReportsRecCount" SelectMethod="GetCardFeesReport" OnSelected="objCardFeesReport_Selected"> <SelectParameters> <asp:Parameter Name="sortExpression" Type="String" /> <asp:Parameter Name="filteredBy" Type="String" /> <asp:Parameter Name="startRowIndex" DefaultValue="0" Type="Int32" /> <asp:Parameter Name="maximumRows" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> <asp:GridView ID="gvCardFeesRReport" runat="server" PageSize="10" AllowSorting="true" AllowPaging="true" AutoGenerateColumns="false" CellPadding="5" CellSpacing="0" Width="100%" DataSourceID="objCardFeesReport" CssClass="GridMain" OnPageIndexChanging="gvCardFeesRReport_PageIndexChanging" OnSorting="gvCardFeesRReport_Sorting" OnRowCommand="gvCardFeesRReport_RowCommand" > <HeaderStyle CssClass="HeaderRow" /> <RowStyle CssClass="NormalRow" /> <AlternatingRowStyle CssClass="AlternateRow" /> <PagerStyle CssClass="PagingRow" HorizontalAlign="Right" Height="20px" /> <SelectedRowStyle CssClass="HighlightedRow" /> <EmptyDataRowStyle CssClass="NoRecords" /> <EmptyDataTemplate> <asp:Label ID="lblNoRecords" Text="Your search did not yield any result." runat="server"> </asp:Label> <p> Suggestions:</p> <li>Try different Filter.</li> <li>There may be no records in the system.</li> </EmptyDataTemplate> <Columns> <asp:BoundField HeaderStyle-CssClass="gridViewHeader" DataField="AccountNumber" SortExpressio

                  I Offline
                  I Offline
                  Ibrahim Bello
                  wrote on last edited by
                  #8

                  1. Why not do your pagination in the PageIndex_Changing event of the gridview rather than in the RowCommand event? 2. Where you have:

                  for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                  {
                  String feeID = ds.Tables[0].Rows[i]["TRANTYPEID"].ToString();
                  Decimal feeAmount = Convert.ToDecimal(ds.Tables[0].Rows[i]["TRANSACTIONAMOUNT"]);

                  you can substitute with:

                  int pageOffset = 10 * gvCardFeesRReport.PageIndex;

                  for (int i = 0; i < gvCardFeesRReport.Rows.Count - 1; i++)
                  {
                  String feeID = ds.Tables[0].Rows[i + pageOffset]["TRANTYPEID"].ToString();
                  Decimal feeAmount = Convert.ToDecimal(ds.Tables[0].Rows[i + pageOffset]["TRANSACTIONAMOUNT"]);

                  3. If all these don't work, try populating your gridview programmatically to achieve more control over your data. Hope this helps

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups