6

Anyone got an explanation of what's going on? Changing code 1 to code 2 fixes the problem -although theoretically there should be no difference. (Theory hits practice like a pumpkin hitting a brick wall).


Code 1:

 OutputDataGridView.DataSource = myList;

Code 2:

 OutputDataGridView.DataSource = null;
 OutputDataGridView.DataSource = myList;
Michael Myers
  • 188,989
  • 46
  • 291
  • 292
Larry Watanabe
  • 10,126
  • 9
  • 43
  • 46
  • Where in the page's life-cycle is the datasource assigned and under what condition (if any)? – o.k.w Dec 07 '09 at 07:57
  • I'm creating a simple form to add a new User object to a list of User objects. Initially the DataSource is assigned to the existing list of User objects. After populating the new User object from a bunch of text fields in the form, the new object is added to the list. No update. I tried re-assigning to the same list - i.e. Code 1. No update. I changed to Code 2, and voila - it works. – Larry Watanabe Dec 07 '09 at 08:07

1 Answers1

1
protected void btnWhateverClick(object sender, EventArgs e)
{
    myGridView.DataSourceID = String.Empty;
    myGridView.DataSource = new int[0];
    myGridView.DataBind();
}

and you're done.

For Ref DataSource in gridview

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
ACP
  • 34,682
  • 100
  • 231
  • 371