C# c中的分页和行命令#

C# c中的分页和行命令#,c#,pagination,rowcommand,C#,Pagination,Rowcommand,在我的cs页面的代码隐藏中,我插入了分页: protected void Paginate(object sender, CommandEventArgs e) { int intCurIndex = gvProducts.PageIndex; switch (e.CommandArgument.ToString().ToLower()) { case "First": gvProducts.PageIndex = 0;

在我的cs页面的代码隐藏中,我插入了分页

protected void Paginate(object sender, CommandEventArgs e)
{
    int intCurIndex = gvProducts.PageIndex;

    switch (e.CommandArgument.ToString().ToLower())
    {
        case "First":
            gvProducts.PageIndex = 0;
            break;
        case "Prev":
            gvProducts.PageIndex = intCurIndex - 1;
            break;
        case "Next":
            gvProducts.PageIndex = intCurIndex + 1;
            break;
        case "Last":
            gvProducts.PageIndex = gvProducts.PageCount - 1;
            break;
    }
    gvProducts.DataBind();
}
但是如果将代码添加到我的cs页面的行命令事件后,此分页将不起作用:

protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
    GridView g2 = (GridView)gvProducts.Rows[rowindex].FindControl("GridView2");

    if (e.CommandName == "Details")
    {
       ....
    }
    else
    {
       ....
    }
}
这是错误,如何解决此问题:

输入字符串的格式不正确

在这一行:

int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
编辑#01

<PagerTemplate>
    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/aspnet/img/bot_back_doppio.gif"
        CommandArgument="First" CommandName="Page" />
    <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/aspnet/img/bot_back.gif"
        CommandArgument="Prev" CommandName="Page" />
    Page
        <asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True" CssClass="ddl_Class"
            OnSelectedIndexChanged="DDLPages_SelectedIndexChanged">
        </asp:DropDownList>
    of
        <asp:Label ID="lblPageCount" runat="server"></asp:Label>
    <asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="/aspnet/img/bot_next.gif"
        CommandArgument="Next" CommandName="Page" />
    <asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/aspnet/img/bot_next_doppio.gif"
        CommandArgument="Last" CommandName="Page" />
</PagerTemplate>

调用
Paginate
方法时?您在
e.CommandArgument
中得到的值是多少?调用
gvProducts\u RowCommand
时?您是否在aspx中将行索引设置为e.CommandArgument?您可以查看以了解它是如何在RowCommand事件中获取行索引的。@ChetanRanpariya感谢您的帮助,请参阅我的第一篇文章中的编辑#01question@ChetanRanpariya非常感谢。在我的第一个问题中关于编辑#03的解决方案
  <asp:GridView ID="gvProducts" AutoGenerateColumns="False" EmptyDataText="Empty" EnableViewState="true"
        runat="server" DataKeyNames="sID" CssClass="mGrid" HorizontalAlign="Center"
        AllowPaging="True" PageSize="15"
        OnPageIndexChanging="gvProducts_PageIndexChanging"                 
        OnRowEditing="gvProducts_RowEditing"
        OnRowCancelingEdit="gvProducts_RowCancelingEdit"
        OnRowDataBound="gvProducts_RowDataBound"
        OnRowUpdating="gvProducts_RowUpdating"
        OnRowCommand="gvProducts_RowCommand">
protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName != "Page")
    {
        int rowindex = Convert.ToInt32(e.CommandArgument.ToString());
        GridView g2 = (GridView)gvProducts.Rows[rowindex].FindControl("GridView2");

       if (e.CommandName == "Details")
       {
        ....
       }
       else
       {
       ....
       }
    }
}