title: Setting GridView's DataSourceId to "", causes GridView to lose
body: <p><br /><br /></p>
  
  <p>If I bind GridView to SqlDataSource, then the first time page will be created, GridView will display columns retrieved from data source. But if on postback I set GridView.DataSourceID to null or to an empty string</p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
               ...
          if (IsPostBack)
              GridView1.DataSourceID = "";
               ...
      }
  </code></pre>
  
  <p>, then GridView won’t display any rows at all. But why is that? </p>
  
  <p>Assuming GridView has EnableViewstate set to true, then it should be able to display rows it retrieved from data source when page was first created! 
  I realize one could argue that Framework notices that DataSourceId has changed and assumes GridView doesn't need data from previous data source, but I’d assume Framework would realize that empty string or null reference doesn’t point to any of data source and thus wouldn’t remove any data GridView retrieved from previous data source?! </p>
  
  <p><br /></p>
  
  <p>thank you</p>
  
  <p><br /></p>
  
  <p>EDIT:
  <br />
  Hello,
  <br /></p>
  
  <blockquote>
    <p>Basically what is going on is once you have set the DataSourceID to null or an empty string the control takes this as an indication from the consumer of the control that they do not wish to bind any data at all (even ViewState data). The control checks the DataSourceID prior to binding and if it is an empty string then it does not DataBind in its EnsureDataBound method.</p>
  </blockquote>
  
  <p><br /></p>
  
  <p>So if you set DataSourceID to null inside Page_Load(), but GridView only checks DataSourceId moments before binding ( which happens much after Page_Load ), then until DataSourceId is checked, ViewState containing data from previous data source should still be available inside Page_Load() ( and still available,for example,inside an event handler subscribed to an event that caused a postback)?! </p>