+ -
当前位置:首页 → 问答吧 → GridView里面的自定义分页按钮点击无反应是什么原因?

GridView里面的自定义分页按钮点击无反应是什么原因?

时间:2011-12-18

来源:互联网

这是aspx前台代码(GridView里面的PagerTemplate):
C# code

                <PagerTemplate>
                <table width="80%" style="font-size:12px;">
                    <tr>
                        <td style="text-align:center"><asp:Label ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>'></asp:Label>/<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>&nbsp;&nbsp;
                            <asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False"
                                CommandName="Page" Text="首页" CommandArgument="first" OnCommand="gvPage_Command">
                            </asp:LinkButton>
                            <asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False"
                                CommandName="Page" Text="上一页" CommandArgument="prev" OnCommand="gvPage_Command">
                            </asp:LinkButton>
                            <asp:LinkButton ID="btnNext" runat="server" CausesValidation="False"
                                CommandName="Page" Text="下一页" CommandArgument="next" OnCommand="gvPage_Command">
                            </asp:LinkButton>
                            <asp:LinkButton ID="btnLast" runat="server" CausesValidation="False"
                                CommandName="Page" Text="尾页" CommandArgument="last" OnCommand="gvPage_Command">
                            </asp:LinkButton>&nbsp;&nbsp;
                            <asp:TextBox ID="txtPageIndex" runat="server" Width="20"></asp:TextBox>
                            <asp:Button ID="btnGo" runat="server" Text="GO" CausesValidation="false" CommandName="Page"  CommandArgument="go" OnCommand="gvPage_Command"   />
                        </td>
                    </tr>
                </table>
                </PagerTemplate>



这是cs后台代码:
C# code

protected void gvPage_Command(object sender, EventArgs e)
        {
            try
            {
                switch (((LinkButton)sender).CommandArgument.ToString())
                {
                    case "first":
                        gvSearch.PageIndex = 0;
                        break;
                    case "last":
                        gvSearch.PageIndex = gvSearch.PageCount - 1;
                        break;
                    case "prev":
                        if (gvSearch.PageIndex > 0)
                        {
                            gvSearch.PageIndex -= 1;
                        }
                        break;
                    case "next":
                        if (gvSearch.PageIndex < gvSearch.PageCount - 1)
                        {
                            gvSearch.PageIndex += 1;
                        }
                        break;
                    case "go":
                        GridViewRow gvr = gvSearch.BottomPagerRow;
                        TextBox txtPageIndex = (TextBox)gvr.FindControl("txtPageIndex");
                        int index = Convert.ToInt32(txtPageIndex.Text);
                        if (index > 0 && index < gvSearch.PageCount)
                        {
                            gvSearch.PageIndex = index - 1;
                        }
                        break;
                }
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (ViewState["gsql"] != null)
                {
                    string gsql = ViewState["gsql"].ToString();
                    BindGrid(gsql);
                }
            }
        }



我在方法里面设置了断点,可是就是进不去,用OnCommand、OnClick和GridView的RowCommand都没反应,这是为什么呢?

作者: q380472335   发布时间: 2011-12-18

求教啊求教啊拜托..小弟真搞不懂

作者: q380472335   发布时间: 2011-12-18

有个事件写上没有
GridView_Page PageIndexChanging()
{
` GridView.PageIndex = e.NewPageIndex;
}

作者: GavinZL   发布时间: 2011-12-18