ASP.Net GridView strange edit behaviour with paging

I have an ObjectDataSource\[code\]<asp:ObjectDataSource SelectCountMethod="GetCount" EnablePaging="true" SortParameterName="sortExpression" ID="customersDS" runat="server" SelectMethod="GetList" TypeName="expenses.Classes.ExpenseFactory" DeleteMethod="Delete" UpdateMethod="Update" > <SelectParameters> <asp:ControlParameter ControlID="IdHidden" PropertyName="Value" Name="userId" /> <asp:Parameter DbType='Boolean' DefaultValue='http://stackoverflow.com/questions/14480498/false' Name='isExpense' /> <asp:Parameter DbType='Boolean' DefaultValue='http://stackoverflow.com/questions/14480498/false' Name='containRepeated' /> <asp:ControlParameter DbType="Int32" DefaultValue="" ControlID="CategorySelector2" Name="categoryId" /> <asp:ControlParameter DbType="DateTime" DefaultValue="" ControlID="FromSpentDateCalendarBox" Name="from" /> <asp:ControlParameter DbType="DateTime" DefaultValue="" ControlID="ToSpentDateCalendarBox" Name="to" /> </SelectParameters> <UpdateParameters> <asp:ControlParameter ControlID="IdHidden" PropertyName="Value" Name="userId" /> <asp:Parameter DbType='Boolean' DefaultValue='http://stackoverflow.com/questions/14480498/false' Name='isExpense' /> </UpdateParameters> </asp:ObjectDataSource>\[/code\]connected to a GridView\[code\]<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" DataSourceID="customersDS" CssClass="gtable sortable width100" DataKeyNames="Id" AlternatingRowStyle-CssClass="odd" CellPadding="0" GridLines="None" OnPreRender="PreRender" OnRowDataBound="GridView1_RowDataBound" >\[/code\]with edit and delete buttons in a CommandField\[code\]<asp:CommandField ItemStyle-Width="75px" HeaderStyle-Font-Bold=true HeaderText="<%$ Resources:Default, Actions %>" EditImageUrl="~/img/edit.png" ButtonType='Image' ShowEditButton="True" UpdateImageUrl="~/img/save.gif" CancelImageUrl="~/img/cancel.png" > <ControlStyle CssClass="my_edit_buttons" /> </asp:CommandField>\[/code\]Everything is located inside and UpdatePanel. The GridView and ObjectDataSource support and use paging. Paging works without any problems. The problem is editing. When I click edit on the first page, everything works as expected. When I click edit on the n-th item on the second or other page (greater than one), the GridView switches to the first page and selected the n-th item for editing. (More concerete example: I switch to the second page, I select the item number 2 on that page to be edited, the GridView switches to the first page and selects the item number 2 (on the first page) to be edited).Any ideas what may be the problem?EDIT:PreRender (setting GridView header):\[code\] protected void PreRender(object sender, EventArgs e) { try { GridView1.UseAccessibleHeader = false; GridView1.HeaderRow.TableSection = TableRowSection.TableHeader; } catch { } }\[/code\]RowDataBound (changind delete button to a custom one with configmation prompt|:\[code\] protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // we are using a html anchor and a hidden asp:button for the delete HtmlAnchor linkDelete = (HtmlAnchor) e.Row.FindControl("linkDelete"); ImageButton btnDelete = (ImageButton) e.Row.FindControl("btnDelete"); string prompt = Resources.Default.DeletePrompt; linkDelete.Attributes["onclick"] = string.Format(prompt, btnDelete.ClientID); Expense expense = e.Row.DataItem as Expense; if (expense!=null) { if (expense.SpentDate>DateTime.Now) { e.Row.CssClass = "future"; } } e.Row.Cells[1].CssClass = e.Row.Cells[4].CssClass = "red"; }\[/code\]
 
Back
Top