Faye_DBA
asked on
Allow paging of a GridView does not move to the record on the next page.
This is my Gridview:
<asp:GridView ID="GrdVwBuyUpContribution s" runat="server" AutoGenerateColumns="False "
OnRowEditing="GrdVwBuyUpCo ntribution s_Click" OnRowUpdating="GrdVwBuyUpC ontributio ns_update" OnRowCancelingEdit="GrdVwB uyUpContri butions_Ro wCanceling Edit" OnPageIndexChanging="GrdVw BuyUpContr ibutions_P ageIndexCh anging"
BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" HorizontalAlign="Left" DataKeyNames="Contribution _ID"
Width="300" AllowPaging="True" PageSize="10" >
<Columns>
<asp:CommandField ShowEditButton="True"></as p:CommandF ield>
<asp:TemplateField HeaderText="Contribution Date" HeaderStyle-HorizontalAlig n="Left">
<ItemTemplate>
<%# Eval("Date") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="DateTextBox" Text='<%# Eval("Date")%>' runat="server"></asp:TextB ox>
<asp:RequiredFieldValidato r ID="RequiredFieldValidator 1" runat="server" ErrorMessage="You must enter a valid date."
ControlToValidate="DateTex tBox">
*</asp:RequiredFieldValida tor>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="You must provide a valid Date.."
ControlToValidate="DateTex tBox" Operator="DataTypeCheck" Type="Date">
*</asp:CompareValidator>
<cc1:CalendarExtender ID="CalendarExtender1" TargetControlID="DateTextB ox" Format="yyyy/MM/dd"
runat="server">
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" HeaderStyle-HorizontalAlig n="Left">
<ItemTemplate>
<%# string.Format("{0:c}", Eval("Amount"))%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="AmountTextBox" Text='<%# string.Format("{0:0.00}", Eval("Amount"))%>' runat="server"></asp:TextB ox>
<asp:RequiredFieldValidato r ID="RequiredFieldValidator 2" runat="server" ErrorMessage="You must enter an amount."
ControlToValidate="AmountT extBox">
*</asp:RequiredFieldValida tor>
<asp:CompareValidator ID="CompareValidator2" runat="server" ErrorMessage="You must provide a valid currency value for the Amount."
ControlToValidate="AmountT extBox" Operator="DataTypeCheck" Type="Currency">
*</asp:CompareValidator>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
This is the code when pageIndex changes:
protected void GrdVwBuyUpContributions_Pa geIndexCha nging(Obje ct sender, GridViewPageEventArgs e)
{
// Cancel the paging operation if the user attempts to navigate
// to another page while the GridView control is in edit mode.
if (GrdVwBuyUpContributions.E ditIndex != -1)
{
// Use the Cancel property to cancel the paging operation.
e.Cancel = true;
// Display an error message.
int newPageNumber = e.NewPageIndex + 1;
lblMessage.Text = "Please update the record before moving to page " +
newPageNumber.ToString() + ".";
}
else
{
// Clear the error message.
lblMessage.Text = "";
}
However when I click on any of the page numbers on the page, the gridview does not do what it is supposed to do.
Why?
<asp:GridView ID="GrdVwBuyUpContribution
OnRowEditing="GrdVwBuyUpCo
BackColor="White" BorderColor="#E7E7FF"
BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" HorizontalAlign="Left" DataKeyNames="Contribution
Width="300" AllowPaging="True" PageSize="10" >
<Columns>
<asp:CommandField ShowEditButton="True"></as
<asp:TemplateField HeaderText="Contribution Date" HeaderStyle-HorizontalAlig
<ItemTemplate>
<%# Eval("Date") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="DateTextBox" Text='<%# Eval("Date")%>' runat="server"></asp:TextB
<asp:RequiredFieldValidato
ControlToValidate="DateTex
*</asp:RequiredFieldValida
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="You must provide a valid Date.."
ControlToValidate="DateTex
*</asp:CompareValidator>
<cc1:CalendarExtender ID="CalendarExtender1" TargetControlID="DateTextB
runat="server">
</cc1:CalendarExtender>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" HeaderStyle-HorizontalAlig
<ItemTemplate>
<%# string.Format("{0:c}", Eval("Amount"))%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="AmountTextBox" Text='<%# string.Format("{0:0.00}", Eval("Amount"))%>' runat="server"></asp:TextB
<asp:RequiredFieldValidato
ControlToValidate="AmountT
*</asp:RequiredFieldValida
<asp:CompareValidator ID="CompareValidator2" runat="server" ErrorMessage="You must provide a valid currency value for the Amount."
ControlToValidate="AmountT
*</asp:CompareValidator>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
This is the code when pageIndex changes:
protected void GrdVwBuyUpContributions_Pa
{
// Cancel the paging operation if the user attempts to navigate
// to another page while the GridView control is in edit mode.
if (GrdVwBuyUpContributions.E
{
// Use the Cancel property to cancel the paging operation.
e.Cancel = true;
// Display an error message.
int newPageNumber = e.NewPageIndex + 1;
lblMessage.Text = "Please update the record before moving to page " +
newPageNumber.ToString() + ".";
}
else
{
// Clear the error message.
lblMessage.Text = "";
}
However when I click on any of the page numbers on the page, the gridview does not do what it is supposed to do.
Why?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.