I have a grid which displays on a webpage with 20 rows per page. The user can then search through it, click on rows. If the user decides to click a row, then the following happens:\[code\] int ReaderRowIsGridRow = 0; while (reader.Read()) { if (ReaderRowIsGridRow == ((e.Row.RowIndex + (20 * (GridViewControl.PageIndex))))) { e.Row.Attributes["onclick"] = "window.location.href='http://stackoverflow.com/questions/14443491/CustomerDetails.aspx?CustomerID=" + reader.GetValue(reader.GetOrdinal("CustomerID")).ToString() + "'"; } ReaderRowIsGridRow += 1; }\[/code\]So based on the above code, we know which row on which page is clicked.Let's say we have someone called 'Adam' and another called 'Zoe'.Adam appears at the top of the database automatically because his name begins with a. If you click on his row, then you can see his details. However, if you click on the first name row header to sort, Zoe will be at the top. The problem is, when you click Zoe, you still get Adams details.In case I am missing something, here is the GridView code:\[code\] <Control:GridViewControl ID="GridViewControl" runat="server" AllowPaging="True" CellPadding="4" ForeColor="#333333" PageSize="20" OnPageIndexChanging="GridViewControlPageIndexChanging" GridLines="None" PagerType="DropDownList" HeaderStyle-HorizontalAlign="Left" Width="100%" AutoGenerateColumns="False" CssClass="GridViewControl" PagerStyle-CssClass="PagerGridViewControlPager" RowStyle-CssClass="RowStyleGridViewControl" ClientIDMode="Static" OnRowDataBound="GridViewControlRowDataBound" AllowSorting="true" OnSorting="GridViewControlSorting"> <RowStyle BackColor="#F7F6F3" ForeColor="#333333"></RowStyle> <PagerStyle BackColor="#284775" ForeColor="#FFFFFF"></PagerStyle> <HeaderStyle BackColor="#5D7B9D" ForeColor="#FFFFFF" Font-Bold="True"></HeaderStyle> <AlternatingRowStyle BackColor="#FFFFFF" ForeColor="#284775"></AlternatingRowStyle> <Columns> <asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" ItemStyle-Width="14.28%" /> <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" ItemStyle-Width="10%" /> <asp:BoundField DataField="County" HeaderText="County" SortExpression="County" ItemStyle-Width="10%" /> </Columns> </Control:GridViewControl>And here is the method in question: protected void GridViewControlRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //Uses a stored procedure to display the customer details. SqlConnection conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["Customers"].ConnectionString; conn.Open(); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; cmd.CommandText = "searchCustomerTable"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar); cmd.Parameters.Add("@Surname", SqlDbType.NVarChar); cmd.Parameters.Add("@City", SqlDbType.NVarChar); cmd.Parameters.Add("@County", SqlDbType.NVarChar); cmd.Parameters["@FirstName"].Value = http://stackoverflow.com/questions/14443491/txtFirstName.Text; cmd.Parameters["@Surname"].Value = http://stackoverflow.com/questions/14443491/txtSurname.Text; cmd.Parameters["@City"].Value = http://stackoverflow.com/questions/14443491/txtCity.Text; cmd.Parameters["@County"].Value = http://stackoverflow.com/questions/14443491/txtCounty.Text; reader = cmd.ExecuteReader(); e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';"; e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';"; int ReaderRowIsGridRow = 0; while (reader.Read()) { if (ReaderRowIsGridRow == ((e.Row.RowIndex + (20 * (GridViewControl.PageIndex))))) { e.Row.Attributes["onclick"] = "window.location.href='http://stackoverflow.com/questions/14443491/CustomerDetails.aspx?CustomerID=" + reader.GetValue(reader.GetOrdinal("CustomerID")).ToString() + "'"; } ReaderRowIsGridRow += 1; } conn.Close(); } }\[/code\]