Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1022531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:28:49+00:00 2026-05-16T11:28:49+00:00

GridView <asp:GridView ID=GridView1 runat=server AllowPaging=True AllowSorting=True PagerSettings-Position=TopAndBottom PagerSettings-Mode=Numeric PageSize=40 CellPadding=4 DataSourceID=dsEquipmentGridView ForeColor=#333333 GridLines=Horizontal Style=font-size:

  • 0

GridView

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
    AllowSorting="True" PagerSettings-Position="TopAndBottom"
    PagerSettings-Mode="Numeric" PageSize="40" CellPadding="4" DataSourceID="dsEquipmentGridView"
    ForeColor="#333333" GridLines="Horizontal" Style="font-size: x-small" AutoGenerateColumns="False"
    DataKeyNames="IREF" OnRowEditing="GridView1_RowEditing" OnRowUpdated="GridView1_RowUpdated"
    OnSorted="GridView1_Sorted" OnSorting="GridView1_Sorting" OnPageIndexChanged="GridView1_PageIndexChanged1"
    OnPageIndexChanging="GridView1_PageIndexChanging" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
    OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowCommand="GridView1_RowCommand"
    BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" 
    OnRowCancelingEdit="GridView1_RowCancelingEdit" onload="GridView1_Load" 
    ondatabound="GridView1_DataBound">
    <PagerSettings Position="TopAndBottom" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <Columns>
 <asp:CommandField ShowDeleteButton="False" ShowSelectButton="true" EditText="QuickEdit"
     HeaderText="Manage" SelectText="Manage" />

For the first page loaded, it shows the correct DataKey value if I click on the command field.

However if I change to the next page of results, upon selecting a record the corresponding value is incorrect. It seems to keep the previous page information. How do I overcome this?

EDIT:

In the GridView1_SelectedIndexChanged method, I used the following:

    // Determine the index of the selected row.
    int index = GridView1.SelectedIndex;

    // Display the primary key value of the selected row.
    HttpContext.Current.Response.Write("The primary key value of the selected row is " + GridView1.DataKeys[index].Value.ToString() + ".<br>");

    GridViewRow row = GridView1.Rows[index];

    int rowindex = row.RowIndex;
    HttpContext.Current.Response.Write("rowindex-> " + rowindex.ToString() + "<br>");

    int ID = (int)GridView1.DataKeys[row.DataItemIndex - (GridView1.PageIndex * GridView1.PageSize)].Value;

    HttpContext.Current.Response.Write("row.DataItemIndex" + ID.ToString()+"<br>");

    int Userid = Convert.ToInt32(GridView1.DataKeys[index].Value);

    HttpContext.Current.Response.Write("Userid" + Userid.ToString() + "<br>");

I am unable to get the correct value after paging.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:28:50+00:00Added an answer on May 16, 2026 at 11:28 am

    Fixed a while ago. Was using a thrid party GridView helper class. Which broke the normal functionality of the GridView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False AllowPaging=true AllowSorting=true PageSize=10 DataKeyNames=CategoryID onselectedindexchanged=GridView1_SelectedIndexChanged GridLines=Vertical onrowediting=GridView1_RowEditing onrowcancelingedit=GridView1_RowCancelingEdit onrowupdating=GridView1_RowUpdating onsorted=GridView1_Sorted
Sample <asp:GridView ID=data_basic_addresses runat=server AllowPaging=False BorderWidth=0 AllowSorting=True AutoGenerateColumns=False DataKeyNames=AddressId HorizontalAlign=Center DataSourceID=LinqAddressDS PageSize=20 CssClass=GridViewClass> <Columns>
<asp:GridView ID=GridView2 runat=server AllowPaging=True AllowSorting=True AutoGenerateColumns=False DataSourceID=LinqDataSource1> <Columns> <asp:BoundField DataField=UserName HeaderText=User Name ReadOnly=True SortExpression=UserName
<asp:GridView ID=gridInboxMessage runat=server AllowPaging=True AllowSorting=True AutoGenerateColumns=False DataSourceID=LinqDataSource1 OnSelectedIndexChanged=gridInboxMessage_SelectedIndexChanged> <Columns> <asp:TemplateField> <ItemTemplate> <asp:Button runat=server ID=DeleteInbox
I have a gridview like below: <asp:GridView DataKeyNames=TransactionID AllowSorting=True AllowPaging=TrueID=grvBrokerage runat=server AutoGenerateColumns=False CssClass=datatable Width=100%
<asp:GridView ID=GridView2 runat=server AllowPaging=True AutoGenerateColumns=False DataSourceID=opendiarysource Font-Size=Small style=font-size: 8pt; border-top-style: solid; border-right-style: solid; border-left-style:
Here is my GridView: <div> <asp:GridView ID=MainGridView runat=server AllowPaging=True DataSourceID=GridViewDataSource EnableModelValidation=True CssClass=mGrid PagerStyle-CssClass=pgr AlternatingRowStyle-CssClass=alt
My SortedAscendingHeaderStyle and SortedDescendingHeaderStyle is not working at all <asp:GridView ID=grdProducts runat=server CssClass=grid AllowPaging=True
protected void GridView1_DataBound(object sender, EventArgs e) { GridView1.Columns[0].ItemStyle.Width = 400; <asp:GridView ID=GridView1 runat=server DataSourceID=ObjectDataSource1
I have a Gridview <asp:GridView ID=GridView1 runat=server Width=400px AutoGenerateColumns=false OnSelectedIndexChanged=GridView1_SelectedIndexChanged1> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.