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 1053259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:13:27+00:00 2026-05-16T17:13:27+00:00

I am having a problem updating a datatable that is bound to a datagrid.

  • 0

I am having a problem updating a datatable that is bound to a datagrid. Tried a bunch of approaches but the problem is the underlying datatable reverts back to its initial state everytime u click a command.

Here’s the example code:

On Label Click:

protected void OnUserDataGridCommand(object source, DataGridCommandEventArgs e)
        {
            DataTable dt = DataGridUsers.DataSource as DataTable;

            if (e.CommandName == "Lock Out")
            {
                // Approach 1
                e.Item.Cells[0].Text = "Lock";
                DataGridUsers.DataSource = dt;
                DataGridUsers.DataBind();

                // Approach 2              
                dt.Rows[e.Item.ItemIndex]["FirstName"] = "LOCK";
                dt.Rows[e.Item.ItemIndex].AcceptChanges();

                DataGridUsers.DataSource = dt;
                DataGridUsers.DataBind();                
            }
        }

So this will update the row’s first name to say Lock but when you click on another row the previously Locked will revert to the first name. When I breakpoint regardless of a row displaying lock, the datatable always is the initial data (no “LOCK” data).

  • 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-16T17:13:27+00:00Added an answer on May 16, 2026 at 5:13 pm

    This line typically doesn’t work for me

    DataTable dt = DataGridUsers.DataSource as DataTable;
    

    You might want to instead manage the DataSource in the session, by retrieving it out of session doing your modifications and then rebind it to the Grid.

    You might also want to take a look at where the DataSource got bound to the grid the first time. Is is it running on the postback thus overwriting your changes.

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

Sidebar

Related Questions

I'm having a problem updating a table and im sure its pretty straight forward
I've a little problem, with a ASPX .NET application that I'm updating. After having
I'm having problem with datagrid view. I have attached an image with the code
I am having a problem updating the view in android every x seconds. To
I'm having a problem updating a row after an inline edit. My ColModel is:
I am having an update statament in my jsp. The problem is that when
I have a listview and also a DataGrid having records with images. My problem
I am having a problem with the textbox text updating in my view. I
I'm having a problem updating a control on my ui from a thread created
I am having a problem updating several rows of a mysql table using a

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.