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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:34:32+00:00 2026-05-23T13:34:32+00:00

I have a gridview that I databind dynamically in my codebehind. For some reason,

  • 0

I have a gridview that I databind dynamically in my codebehind. For some reason, and only when a user deletes a row from the gridview (using a custom function), after postback, the gridview isn’t refreshed (the deleted value remains). However, if the user were to refresh the gridview in any other way (ie. adding an item, selecting the right item in another tab, etc), it is bound just fine.

I put breakpoints in my codebehind to see what was happening, and apparently the gridview is being bound correctly, and the item that was deleted isn’t in it’s gridview.DataSource.

Here is my code, so if you see what I don’t, just let me know!

Delete Row-Command:

if (e.CommandName == "delete")
        {
            int selectedId = int.Parse(e.CommandArgument.ToString());
            //delete selected row from database
            var item = (Item)DataContext.Items.Where(item => item.ItemId == selectedId).Single();
            if (item != null)
            {
                DataContext.CompanyGoalPrograms.DeleteObject(item);
            }
            DataContext.SaveChanges();

            bindGridView(currentId); //firing, but not refreshing gv after postback
            // currentId is a static variable
        }

bindGridView method (works every other time its called, so I don’t think the problem is here):

protected void bindGridView(long thisId)
    {
        var query = from items in DataContext.Items
                    where items.SubSomething.Something.SomethingId == thisId && goals.SubSomething.YearId == selectedYearId //<--another static variable
                    select items;
        Gridview1.DataSource = from items in query.AsEnumerable()
                                    select new
                                    {
                                        items.Field1,
                                        items.Field2,
                                        items.Field3,
                                        Field4 = ((decimal)items.Field4).ToString("N2"),
                                        Field5 = ((decimal)items.Field5).ToString("N2"),
                                        Field6 = String.Format("{0:#,##0}", (long)items.Field6),
                                        Field7 = items.Field4 == null ? "$0.00" : ((decimal)items.Field7).ToString("C"),
                                    };
        Gridview1.DataBind();
     }

[EDIT]
The funny thing is, not only does it run, but when I check the contents of the datasource after its been run (whilst debugging), the item that was deleted actually is removed from the datasource, it just doesn’t show the changes to the user.

  • 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-23T13:34:33+00:00Added an answer on May 23, 2026 at 1:34 pm

    I figured out the problem:

    Gridviews have predefined commands set up, such as ‘select’, ‘edit’, and ‘delete’. When I try to define my own event to run with the command name ‘delete’, the program will try and run parts of my event alongside it’s predefined event. This is what has been causing issues.

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

Sidebar

Related Questions

I have a gridview that is using a LinqDataSource for it's datasource. I've added
I have a gridview that I have added a checkbox column using a templatefield
I have a ASP.NET GridView that uses template columns and user controls to allow
I'm currently building a Gridview that has expandable rows. Each row contains a dynamically
I have a gridview that I load from a linq query. MyGridData is a
I have a gridview that displays the contents of a database table, using an
I have a GridView that I would like to bind to an ObjectDataSource. I
I have a GridView that allows editing the values in every column, in every
I have a gridview that is within an updatepanel for a modal popup I
I have an gridview that I am adding onclick events to a checkbox column

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.