Unbind a DataSource and clear a DropDownList selection

G

Gaetan

on a test web page, I have two DropDownList fields. The data source for the second DDL field depends
on the value selected in the first DDL.

I want a Reset button that will re-initialize the DDL fields to their initial values. My problem is
that the second DDL cannot be re-initialized to a null/empty state. I do not want to see any data in
thesecond DDL field.

The following code worked in .Net 1.1

ddlField2.DataSource = string.empty;
ddlfield2.DataBind();
ddlFields2.SelectedIndex = 0;

However in .Net 2.0, that same code generates an ArgumentOutofRange expeption the second time the
above code is executed.

Is it possible to unbind a DDL field and have ASP.Net to clear the field on the web page?

Regards,

Gaetan
 
Joined
May 2, 2007
Messages
1
Reaction score
0
Unbind DDL

Try this:

For VB:

ddlField2.DataSource = Nothing
ddlfield2.DataBind()

I'm not familiar with C# but I would guess it would be something like this:

ddlField2.DataSource = null;
ddlfield2.DataBind();
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top