0
我正在使用GridView
控件並且分頁不起作用。在單步執行代碼時,當我單擊頁面時,將調用Page_Load
事件,但我的OnPageIndexChanging
事件從不會被調用。OnPageIndexChanging事件永遠不會在GridView上觸發
<asp:GridView ID="FaxGrid"
runat="server"
BackColor="#FFFFFF"
HeaderStyle-BackColor="#CEDFF2"
HeaderStyle-ForeColor="#316495"
HeaderStyle-Font-Bold="true"
BorderColor="#CEDFF2"
AutoGenerateColumns="false"
OnRowCommand="FaxGridRowCommandHandler"
DataKeyNames="file_id"
AllowPaging="true"
PageSize="10"
PagerSettings-Mode="NumericFirstLast"
OnPageIndexChanging="FaxGrid_PageIndexChanging"
Height="222"
EmptyDataText="No faxes found."
HeaderStyle-Height="35" Width="1470" >
<Columns>
<asp:BoundField HeaderText="File Name" DataField="file_friendly_name" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="125"></asp:BoundField>
<asp:BoundField HeaderText="Dept. Name" DataField="department_name" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="125"></asp:BoundField>
<asp:BoundField HeaderText="Processed" DataField="processed" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="50"></asp:BoundField>
<asp:BoundField HeaderText="First Name" DataField="firstname" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="125"></asp:BoundField>
<asp:BoundField HeaderText="Last Name" DataField="lastname" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="125"></asp:BoundField>
<asp:BoundField HeaderText="DOB" DataField="dob" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="75"></asp:BoundField>
<asp:BoundField HeaderText="Ref. Physician" DataField="referringPhy" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="125"></asp:BoundField>
<asp:BoundField HeaderText="Reported" DataField="reported" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="75"></asp:BoundField>
<asp:BoundField HeaderText="Reported On" DataField="reportedon" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="125"></asp:BoundField>
<asp:BoundField HeaderText="Job Status" DataField="description" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="125"></asp:BoundField>
<asp:TemplateField HeaderText="Fax Options" HeaderStyle-Width="145">
<ItemTemplate>
<asp:Button ID="btnCancel" runat="server" CommandName="CancelFax" CommandArgument='<%# Container.DataItemIndex %>' ToolTip="Cancel and delete fax" Text="Cancel" />
<asp:Button ID="btnResend" runat="server" CommandName="Resend" CommandArgument='<%# Container.DataItemIndex %>' ToolTip="Resend an existing fax." Text="Resend" />
<asp:Button ID="btnSendAsNew" runat="server" CommandName="SendAsNew" CommandArgument='<%# Container.DataItemIndex %>' ToolTip="Send as a new fax." Text="Send as New" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
這裏是隱藏文件我的代碼:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
this.sqlObj = new SqlServer(ConfigurationManager.ConnectionStrings["PdfReceiverConnectionString"].ToString());
this.populateFaxGrid();
}
}
protected void FaxGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.FaxGrid.PageIndex = e.NewPageIndex;
this.FaxGrid.DataSource = this.Session["Faxes"];
this.FaxGrid.DataBind();
}
我明白任何幫助。
我發現了這個問題。 'OnRowCommand'在OnPageChangingIndex事件之前被調用,並且我有一個重定向回到主頁,所以每次我在它有機會點擊OnPageChangingIndex之前都會重定向。愚蠢的錯誤。謝謝阿迪爾。通過重新開始GridView,我發現了這個問題。 – Flea