简体   繁体   English

在Gridview的第二页中编辑行

[英]Edit Row In the Second Page of Gridview

I am having a problem in my gridview, my Gridview has a event of OnPageIndexChanging , the pagesize of my gridview is 20 我在gridview中遇到问题,我的Gridview有一个OnPageIndexChanging事件,我的gridview的页面大小为20

once the record was reach 20 in the first page, the 21st-40th record will go to the second page, when I go to the second page, and I click the edit button in my gridview.. ex: I click the row for 21st record in gridview 一旦记录在第一页达到20,第21至第40条记录将转到第二页,当我转到第二页时,我点击网格视图中的编辑按钮。例如:我点击第21行在gridview中记录

the EditItemTemplate for that row is not showing, but I am not encountering a problem and my code is executing well when I am debugging it. 该行的EditItemTemplate没有显示,但我没有遇到问题,我的代码在调试时执行得很好。

here is my code in "EditRow" in Gridview_RowCommand 这是我在Gridview_RowCommand中的“EditRow”中的代码

protected void gridview_RowCommand(object sender, GridViewCommandEventArgs e)
{

        int iActiveIndex;

        switch (e.CommandName)
        {
            case "EditRow":
                iActiveIndex = Convert.ToInt32(e.CommandArgument);

                gridview.EditIndex = iActiveIndex;

                gridview.DataSource = emp.TrainingPrograms;
                gridview.DataBind();
                break;
         }
}

This is the code in Gridview_OnPageIndexChanging 这是Gridview_OnPageIndexChanging中的代码

protected void gridview_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{

        gridview.DataSource = emp.TrainingPrograms;
        gridview.PageIndex = e.NewPageIndex;
        gridview.DataBind();
}

Is there any possible solution with my problem? 我的问题是否有任何可能的解决方案?

The EditIndex property of the GridView control refers to the Xth row on the current page, not the id of the row to be edited. GridView控件的EditIndex属性引用当前页面上的第X行,而不是要编辑的行的id。

The proper row can be selected by taking the modulus of the rowindex by the pagesize as thus: 可以通过将pagesindex的模数乘以pagesize来选择正确的行,如下所示:

gridview.EditIndex = iActiveIndex % gridview.PageSize;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM