【问题标题】:GridviewPager not route onpaging eventGridviewPager 不路由 onpaging 事件
【发布时间】: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();
    }

【问题讨论】:

    标签: asp.net pager


    【解决方案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();
        }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-06
      • 2017-09-16
      • 2019-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多