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

  • SEARCH
  • Home
  • 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 3309120
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:36:10+00:00 2026-05-17T21:36:10+00:00

This is a bit of a hypothetical question that has sent me off down

  • 0

This is a bit of a hypothetical question that has sent me off down the garden path… Say I have a gridview that I’d like to edit… given a method that binds the data..

private void BindGridFirst() {
        var data = new List<string>() {
            "A","B","C","D","E","F"
        };
        gridView.DataSource = data;
        gridView.DataBind();
    }

Now presume that I’m looking at this page, and another user has come along and made some changes to the underlying data, and I now go and click the edit button to edit D…

The edit method is pretty straight forward:

protected void RowEdit(object sender, GridViewEditEventArgs e) {
        gridView.EditIndex = e.NewEditIndex;
        BindGridSecond();
    }

Edit: I feel compelled to point out, that this method is used in pretty much all the online examples, including ones from Microsoft.

This BindGridSecond() method looks like so:

private void BindGridSecond() {
        var data = new List<string>() {
            "A", "AA", "B","C","D","E","F"
        };
        gridView.DataSource = data;
        gridView.DataBind();
    }

It’s exactly the same, but the data is now changed. Once the UI updates, the user is now in edit mode against row C.

Not what the user expected or wanted. How should this scenario be handled to avoid such an issue?

  • 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-17T21:36:11+00:00Added an answer on May 17, 2026 at 9:36 pm

    Personally, I use the DataKeyNames property and the SelectedDataKey on the GridView, so that I can easily obtain the primary key of the row the user wants, rather than relying on the index of the grid.

    By using the primary key, you don’t have any issues with new items being added to the collection, such as in your example. Plus, using the primary key makes it easier to deal with paging on the grid, as you don’t have to take the page number and index into account.

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

Sidebar

Related Questions

The question is a bit hypothetical. Let's say I have an application that draws
I have a hypothetical set of data with 3 columns that has monthly profit
I have this bit of HTML that is going to be used in multiple
This is a bit hypothetical and grossly simplified but... Assume a program that will
I have this bit of code that is being converted from vb6 to vb.net.
I have this bit of html that I need to parse though <p class=feature_list>
This bit of code comes with new classes that are subclasses of UITableViewController... -
So I have this bit of code for x in range(x1,x2): for y in
I have this bit of code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
i have this bit of code, it limits the Li's to 15 of them

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.