EnableViewState problem

  • Thread starter Thread starter seans
  • Start date Start date
S

seans

Hi, please can someone help with this? I have a dropdown list on an
aspx page bound to a table in an SQL Server database. EnableViewState
is set to true but when I change the entry in the drop down list the
setting doesn't stick and the first item in the list becomes selected.

Is there something else that needs to be done so that the selected item
remains selected?

thanks,

sean
 
One reason could be that the dropdown list is cleared and bound everytime
the page is posted back. Use Page.IsPostback and fill the dropdown
accordingly.

Or, possibly some code logic is changing the selection before it is
accessed?

-Siva

Hi, please can someone help with this? I have a dropdown list on an
aspx page bound to a table in an SQL Server database. EnableViewState
is set to true but when I change the entry in the drop down list the
setting doesn't stick and the first item in the list becomes selected.

Is there something else that needs to be done so that the selected item
remains selected?

thanks,

sean
 
Hi Siva thanks for your reply. Do you mean to code the data binding
like this?

if (!Page.IsPostBack) {

sqlConnection2.Open();
sqlDataAdapter1.Fill(dataSet11);
DropDownList2.DataBind();

}

thanks.

sean
 
Yes. This way the dropdown selection is preserved on further post back.

Hi Siva thanks for your reply. Do you mean to code the data binding
like this?

if (!Page.IsPostBack) {

sqlConnection2.Open();
sqlDataAdapter1.Fill(dataSet11);
DropDownList2.DataBind();

}

thanks.

sean
 
Back
Top