Reputation: 309
I am having a problem in my gridview, my Gridview has a event of OnPageIndexChanging, the pagesize of my gridview is 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
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.
here is my code in "EditRow" in Gridview_RowCommand
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
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?
Upvotes: 1
Views: 1930
Reputation: 1
I got the proper index by adding page size .
Int32 ActiveIndex = Convert.ToInt32(e.NewEditIndex) % gridview.PageSize;
gridview.EditIndex = ActiveIndex + gridview.PageSize;
Upvotes: 0
Reputation: 752
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.
The proper row can be selected by taking the modulus of the rowindex by the pagesize as thus:
gridview.EditIndex = iActiveIndex % gridview.PageSize;
Upvotes: 3