ASP.NET Gridview DataBound event retaining previous value
-
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
-
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
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 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/
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
-
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
You have to post your code for us to know...
-
You have to post your code for us to know...
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
-
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
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!
-
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!
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
-
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
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