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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:26:28+00:00 2026-05-13T22:26:28+00:00

I have a Clear button which sets the gridview datasource to null and binds

  • 0

I have a “Clear” button which sets the gridview datasource to null and binds it. However, when I add a new entry to it, the old rows seem to show up again (in addition to the new row)…not sure what I am doing wrong….

gv.DataSource = null;
gv.DataBind();

Shouldn’t the above clear out the state of the gridview?
TIA

  protected void btnAddFactor_Click(object sender, EventArgs e)
    {

        if (txtfactor.Text != "")
        {
            if (ViewState["factor"] == null)
            {
                DataTable dtbl = new DataTable();
                dtbl.Columns.Add("Factor");
                dtbl.Columns.Add("Weight");
                DataRow dr = dtbl.NewRow();
                dr[0] = txtfactor.Text.Trim();
                dr[1] = Convert.ToInt32(ddlWeight.SelectedValue);
                dtbl.Rows.Add(dr);
                ViewState["factor"] = dtbl;

            }
            else
            {

                DataTable dtbl = (DataTable)(ViewState["factor"]);
                DataRow dr = dtbl.NewRow();
                dr[0] = txtfactor.Text.Trim();
                dr[1] = Convert.ToInt32(ddlWeight.SelectedValue);
                dtbl.Rows.Add(dr);
                ViewState["factor"] = dtbl;

            }
            gvFactor.DataSource = (DataTable)(ViewState["factor"]);
            gvFactor.DataBind();
            //gvFactor.Rows.

        }
    }

   protected void btnClearFactor_Click(object sender, EventArgs e)
    {
        gvFactor.DataSource = null;
        gvFactor.DataBind();
    }
  • 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-13T22:26:28+00:00Added an answer on May 13, 2026 at 10:26 pm

    Are you sure that code is being executed?

    If that doesn’t run the viewstate gets applied and the row (or anything else you have) doesn’t go away.

    Please, include the method that contains that code and the related markup.

    Update:

    Ok, I am looking at the code you added, you saving the stuff in the viewstate, when you clear the gridView and rebind you need to also clear the ViewState (ViewState["factor"] == null), otherwise when you add the other row the old one gets picked up as well as it is still in the viewState:

    protected void btnClearFactor_Click(object sender, EventArgs e)
    {
        ViewState["factor"] == null
    
        // this line you shouldn't need
        gvFactor.DataSource = null;
    
        gvFactor.DataBind();
    }
    

    If you clear the ViewState setting the DataSource to null is also not needed.

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

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can try io:format("~w~n", [ListHere]), which should simply avoid interpreting… May 17, 2026 at 2:57 am
  • Editorial Team
    Editorial Team added an answer Why invent something that's already there? Content-addressable memory May 17, 2026 at 2:57 am
  • Editorial Team
    Editorial Team added an answer Look at AVSystemController_SystemVolumeDidChangeNotification (or alternatively here) May 17, 2026 at 2:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following code: JButton button = new JButton("Clear"); button.addActionListener(this); As far as
I have a clear history button which clears the data in plist. Now, loading
I have several textboxes in a form, and have a button which inserts all
I have a web page with one button and one div. If you click
I have a form with a standard reset button coded thusly: <input type=reset class=button
I have a VB6 application which works with datetime values in SQL Server (which
I have an invoice spreadsheet with comboboxes to select a product which fills out
I have found this example Lazy load of images in ListView from Fedor which
I have a JList component which should be emptied and repopulated. The following code
I have built a long running script to which I have added a progress

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.