Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to unbind a data control... ?

Trying to UNBind a DataBound Control like GridView. I have tried many things but most popular way is to hide it using panel.

I want to know if there is any way to unbind it to null.

C#
GridView1.DataSource = null;
GridView1.DataBind();


I don't see this working ...!!! Any Ideas...????????
Posted
Updated 9-Aug-11 3:03am
v2
Comments
[no name] 9-Aug-11 9:24am    
Please clarify what you are trying to accomplish. What do you mean "unbind"?
the headless nick 9-Aug-11 9:39am    
I m trying to do is - Reset the page to default (starting) scenario like clicking a 'Reset' does in a form. Plus I want to unbind anything that contains anything...
Vivek Krishnamurthy 9-Aug-11 9:27am    
Can you not simply add the data source that does not contain any data ? Such as an empty ObjectDataSource, Datatable etc ?
the headless nick 9-Aug-11 9:40am    
Yups.. but NO.

Please have a look followings,

correct-way-to-unbind-a-bindingsource-from-a-datagridview[^]

system.web.ui.webcontrols.basedataboundcontrol.datasource.aspx[^]

and DataSource is a property of GridView class and set part of the DataSource is work something like below,

C#
...
set
{
  if (value != null)
  {
    //does some sort of validation on value;
  }
  this._dataSource = value;
  ...
}


So null value is acceptable to set DataSource property values.

Hope it helps :)
 
Share this answer
 
v2
Comments
the headless nick 9-Aug-11 9:41am    
Second link was of great help. Superb.. :)) thanks
Mohammad A Rahman 9-Aug-11 17:17pm    
:)
This always works...

C#
GridView1.DataSource = null;
GridView1.DataBind();


Don't know why it wasn't but it works. always... :))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900