Событие GridView OnPageIndexChanging не запускается

Кажется, все в порядке с моим GridView и кодом позади, но событие не срабатывает.

Вот моя Сетка:

   <asp:UpdatePanel ID="ISOSearchUpdatePanel" runat="server">
  <ContentTemplate>           
   <div id="divIsoSelect" style="width:700px; height:60px; background-color:white">

    <fieldset>
        <legend style="font-size: larger; font-weight: bold">Search ISO by</legend>
    <table>
    <tr>
        <td><asp:DropDownList ID="ddlISOSearch" runat="server" AutoPostBack="true"  OnSelectedIndexChanged="ddlISOSearch_SelectedIndexChanged">
            <asp:ListItem Value="">Select...</asp:ListItem>
            <asp:ListItem Value="ISO Number" >ISO Number</asp:ListItem>
            <asp:ListItem Value="Name">Name</asp:ListItem>
            <asp:ListItem Value="Region" >Region</asp:ListItem>
            <asp:ListItem Value="Division">Division</asp:ListItem>

         </asp:DropDownList></td>
   <td >&nbsp;</td>
    <td>
        <asp:Panel ID="pnlSearchEntry" runat="server" Visible="false"   style="width:500px; border:gainsboro; border-width: thick;">
            <table>
            <tr>
                <td valign="middle" style="width:120px"><asp:Label ID="lblEntry"  runat="server" Text=""></asp:Label></td>

                <td valign="top"><asp:TextBox ID="txtSearchValue" runat="server">  </asp:TextBox></td>

                <td valign="top">&nbsp;&nbsp;<asp:Button ID="btnFind" runat="server" Text="Select" OnClick="btnFind_Click"/></td>
            </tr>
            </table>
        </asp:Panel>
    </td>
    </tr>
</table>               
</fieldset>
</div> 
               <asp:GridView ID="grvIsoSearchResults" runat="server" 
                AutoGenerateColumns="false" PageSize="15"
                AllowPaging = "true" Visible="false"  BorderColor="Red" GridLines="Both"
                OnRowCommand="grvIsoSearchResults_RowCommand"
                DataKeyNames="isonum" 
                OnPageIndexChanged="grvIsoSearchResults_PageIndexChanged"
                OnPageIndexChanging="grvIsoSearchResults_PageIndexChanging"
                OnSorting="grvIsoSearchResults_Sorting"                    
                style="position:absolute; top: 120px;">
                <PagerSettings firstpagetext="First" lastpagetext="Last" nextpagetext="Next" pagebuttoncount="100" />
                <Columns>
                   <asp:TemplateField HeaderText="ISONUM" SortExpression="isonum">
                        <ItemTemplate>
                            <asp:Label ID="txtgvIsoNum" Text = '<%# Eval("ISONUM")%>' runat="server" Width="70px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="OFFICE NAME" SortExpression="isoofficename">
                        <ItemTemplate>
                            <asp:Label ID="txtgvIsoOfficeName" Text = '<%# Eval("ISOOFFICENAME")%>' runat="server" Width="200px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="REGION" SortExpression="region">
                        <ItemTemplate>
                            <asp:Label ID="txtgvRegion" Text = '<%# Eval("REGION")%>' runat="server" Width="50px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField> 
                    <asp:TemplateField HeaderText="DIVISION" SortExpression="client_id">
                        <ItemTemplate>
                            <asp:Label ID="txtgvDivision" Text = '<%# Eval("CLIENT_ID")%>' runat="server" Width="50px" style="text-align:center" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="EMAIL ADDRESS">
                        <ItemTemplate>
                            <asp:TextBox ID="txtgvEmailAddress" Text = '<%# Eval("EMAIL")%>' runat="server" Width="200px" />
                            <asp:Button ID="btnEmailUpdate" Text = "Update" runat="server" CommandName="UpdateEmail" onClientClick="return ValidateEmail(this)" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <pagerstyle backcolor="#005482" ForeColor="White" height="30px" verticalalign="Bottom" horizontalalign="Center"/>
            </asp:GridView> 
    </ContentTemplate>
    </asp:UpdatePanel>

И это мои методы code-behind:

    private void SetViewState(DataSet myDataSet)
    {
       ViewState["Data"] = myDataSet;
    } 

    private DataSet GetViewState()
    {
        return (DataSet)ViewState["Data"];
    }

    private void LoadData(String selection, String userInput)
    {
        DataSet ds = new DataSet();
        .
        .
        .
        ds = ISOProcessing.GetISOData(selection, userInput);

        grvIsoSearchResults.DataSource = ds;
        if (ds.Tables[0].Rows.Count > 0)
        {
            SetViewState(ds);
            grvIsoSearchResults.DataBind();
            grvIsoSearchResults.Visible = true;

        }
        else
        {
            lblMsg.ForeColor = System.Drawing.Color.Red;
            this.lblMsg.Text = "No data for current selection";
        }
    }

    protected void grvIsoSearchResults_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
         grvIsoSearchResults.PageIndex = e.NewPageIndex;
         grvIsoSearchResults.DataSource = GetViewState();
         grvIsoSearchResults.DataBind();
    } 

Кажется, все на месте, но когда я хочу перейти на другую страницу во время отладки, точка останова даже не попадает внутрь моего grvIsoSearchResults_PageIndexChanging() метод. Я не уверен, почему это происходит.

Нужна ваша помощь.

Спасибо

2 ответа

Решение

Попробуйте добавить триггер для этого:

    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="grvIsoSearchResults" EventName="PageIndexChanging" />
    </Triggers>
</asp:UpdatePanel>

AutoPostback свойство Gridview не позволяет, пожалуйста, чтобы это правда, как это.

<asp:GridView ID="grvIsoSearchResults" AutoPostback="True" runat="server" 
            AutoGenerateColumns="false" PageSize="15"
            AllowPaging = "true" Visible="false"  BorderColor="Red" GridLines="Both"
            OnRowCommand="grvIsoSearchResults_RowCommand"
            DataKeyNames="isonum" 
            OnPageIndexChanged="grvIsoSearchResults_PageIndexChanged"
            OnPageIndexChanging="grvIsoSearchResults_PageIndexChanging"
            OnSorting="grvIsoSearchResults_Sorting"                    
            style="position:absolute; top: 120px;">
            <PagerSettings firstpagetext="First" lastpagetext="Last" nextpagetext="Next" pagebuttoncount="100" />
            <Columns>
               <asp:TemplateField HeaderText="ISONUM" SortExpression="isonum">
                    <ItemTemplate>
                        <asp:Label ID="txtgvIsoNum" Text = '<%# Eval("ISONUM")%>' runat="server" Width="70px" style="text-align:center" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="OFFICE NAME" SortExpression="isoofficename">
                    <ItemTemplate>
                        <asp:Label ID="txtgvIsoOfficeName" Text = '<%# Eval("ISOOFFICENAME")%>' runat="server" Width="200px" style="text-align:center" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="REGION" SortExpression="region">
                    <ItemTemplate>
                        <asp:Label ID="txtgvRegion" Text = '<%# Eval("REGION")%>' runat="server" Width="50px" style="text-align:center" />
                    </ItemTemplate>
                </asp:TemplateField> 
                <asp:TemplateField HeaderText="DIVISION" SortExpression="client_id">
                    <ItemTemplate>
                        <asp:Label ID="txtgvDivision" Text = '<%# Eval("CLIENT_ID")%>' runat="server" Width="50px" style="text-align:center" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="EMAIL ADDRESS">
                    <ItemTemplate>
                        <asp:TextBox ID="txtgvEmailAddress" Text = '<%# Eval("EMAIL")%>' runat="server" Width="200px" />
                        <asp:Button ID="btnEmailUpdate" Text = "Update" runat="server" CommandName="UpdateEmail" onClientClick="return ValidateEmail(this)" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <pagerstyle backcolor="#005482" ForeColor="White" height="30px" verticalalign="Bottom" horizontalalign="Center"/>
        </asp:GridView> 
Другие вопросы по тегам