unbind a datagrid, datalist, repeater, drop down etc

G

Grant Merwitz

How do you unbind one of these web controls.

I have a drop down list that based on another drop down list selection will
be databouns

private void BindDD2(int id)
{
DD2.DataSource = MyClass.GetList2(id);
DD2.DataBind();
}

Now, if i want to reset this drop down back to its pre bound state, how
would i do this.

I've tried:

1)
DD2.DataSource = null; //didn't work
2)
foreach(ListItem l in DD2.Items)
DD2.Items.Remoce(l); //also don't work
3)
DataSet ds = new DataSet();
DD2.DataSource = ds;
DD2.DataBind(); //this throws an error.


So, any ideas

TIA
 
G

Grant Merwitz

so DD2.Items.Clear() works perfectly on a dropdown
but hows about a DataGrid?
 
L

Lars-Erik Aabech

Depends if you want to keep the column headers. If not, you could just
create an empty data source and bind. :)

DataTable dt = new DataTable();
// Create columns here..
DataGrid1.DataSource = dt;
DataGrid1.DataBind();

Or you could set DataGrid1.EnableViewState = false, and repost the page..

You could even do SELECT * FROM myTable WHERE myId = 0 and fill the data
source, then you'd have the columns, but no data..

The possibilities are many ;)

Lars-Erik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top