GridviewPager 不路由 onpaging 事件

Posted

技术标签:

【中文标题】GridviewPager 不路由 onpaging 事件【英文标题】:GridviewPager not route onpaging event 【发布时间】:2015-06-14 16:55:09 【问题描述】:

我对asp.net gridviewpager 有疑问。当我单击寻呼机任何页面时,它都会路由到OnRowCommand 事件。我正在等待路由OnPageIndexChanging 我已经像这样定义了我的gridview。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"
        GridLines="None" PageSize="4" AllowPaging="True" EmptyDataText="No record found"
        OnPageIndexChanging="OnPaging" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="RowCommand"
        CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
        <Columns>
            <asp:BoundField DataField="Id" HeaderText="Id" />
            <asp:BoundField DataField="Baslik" HeaderText="Baslik" />
            <asp:BoundField DataField="KisaAciklama" HeaderText="Kısa Acıklama" />
            <asp:TemplateField HeaderText="Güncelle">
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="lnkView" CommandArgument='<%#Eval("Id") %>' CommandName="VIEW">Güncelle</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Sil">
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="lnkDelete" CommandArgument='<%#Eval("Id") %>'
                        CommandName="DELETE">Sil</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <%----%>
        </Columns>
    </asp:GridView>

我的后端代码也是

  protected void RowCommand(object sender, GridViewCommandEventArgs e)
    
        LinkButton lnkView = (LinkButton)e.CommandSource;
        string Id = lnkView.CommandArgument;
        if (e.CommandName == "VIEW")
        
            Response.Redirect("/Views/AdminPages/Kayit.aspx?cmd=Update&id="+Id);

        
        else if (e.CommandName == "DELETE")
        

            kayitService.DeleteKayit(Convert.ToInt32(Id));
        
    


    protected void OnPaging(object sender, GridViewPageEventArgs e)
    
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    

【问题讨论】:

【参考方案1】:

请试试这个

<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" BackColor="White"  

BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" onpageindexchange="gvPerson_PageIndexChanging" onrowcancelingedit="gvPerson_RowCancelingEdit" onrowdatabound="gvPerson_RowDataBound" onrowdeleting="gvPerson_RowDeleting" onrowediting="gvPerson_RowEditing" onrowupdating="gvPerson_RowUpdating" onsorting="gvPerson_Sorting">

    <asp:BoundField DataField="Id" HeaderText="Id" />
        <asp:BoundField DataField="Baslik" HeaderText="Baslik" />
        <asp:BoundField DataField="KisaAciklama" HeaderText="Kısa Acıklama" />
        <asp:TemplateField HeaderText="Güncelle">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkView" CommandArgument='<%#Eval("Id") %>' CommandName="VIEW">Güncelle</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Sil">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkDelete" CommandArgument='<%#Eval("Id") %>'
                    CommandName="DELETE">Sil</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <%----%>

</Columns> 

后端代码可能是:

protected void gvPerson_PageIndexChanging(object sender, GridViewPageEventArgs e)
    
        // Set the index of the new display page.  
        Gridview1.PageIndex = e.NewPageIndex;
        // Rebind the GridView control to  
        // show data in the new page. 
        BindGridView();
    

根据我的意见,我上面提到的代码是最适合分页的代码。

【讨论】:

以上是关于GridviewPager 不路由 onpaging 事件的主要内容,如果未能解决你的问题,请参考以下文章

配置RIPv2路由(不自动汇总),或EIGRP路由(不自动汇总),OSPF路由

路由器不关闭,路由器IP就永远不变吗?

Laravel Admin 路由不起作用,但其他路由不起作用

为啥路由存在可以视为路由不匹配(​​RoutingError)?

反应路由器错误:您不应该在路由器之外使用路由

路由器不重启IP会变么