Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,

In my aspx page the DropdownList Items are getting binded when the page is not post back(first time loading) but when I clicked any button like (save ,edit)( all the drop down List items are getting Cleared.

can any one plz help, am i missing any settings for the dropdown list.

I put
Page.EnableViewState = true;
above the If(!ispostback)

The code inside the If(!IsPostback)
is
Parameters param = new Parameters();
DataSet datasetddlInternetwght = new DataSet();
datasetddlInternetwght = param.GetDDLListInternetWght();
ddlIntrntweight.DataTextField = datasetddlInternetwght.Tables[0].Columns["paramname"].ToString();
ddlIntrntweight.DataValueField = datasetddlInternetwght.Tables[0].Columns["paramvalue"].ToString();
ddlIntrntweight.DataSource = datasetddlInternetwght;
ddlIntrntweight.DataBind();


where Parameters is a class in a separate .cs file. I am getting the Data binded when the Page is loaded for the first time but when any button got clicked the items in the Drop down list(ddlIntrntweight) are getting cleared. i enabled the View state for the Drop down list;
Posted
Updated 24-Feb-19 22:11pm
v6

You should enable view state.Go to properties of the DropdownList and set enableviewstate to true.
 
Share this answer
 
Comments
narayana4057 4-Jul-11 0:33am    
Hi thanks for ur information, the Enable View state Property is already true for the Dropdown list.
Please make sure the follow steps:

1) Bind the drop down like
if (!Page.IsPostBack)
       {
           ddlIntrntweight.DataSource = SqlDataSource1;
           ddlIntrntweight.DataBind();
       }


2) Make sure
AutoPostBack="True"

3) Make sure
EnableViewState="True";
 
Share this answer
 
Comments
Tech Code Freak 5-Jul-11 5:27am    
My 5!
Monjurul Habib 5-Jul-11 5:46am    
thank you.
There must be some problem in your code. I would appreciate if you share your code....

++Subhendu
 
Share this answer
 
When you clicked any button of your web page, each time PAGE_LOAD event get called.

what you have written in your PAGE_LOAD() do add the that code under if not post back.

if(! isPostBack)
{
  //Page load code here
}



Hope it helps
 
Share this answer
 
if(! isPostBack)
{
  //I think you put your code here and set the EnableViewState property false;
  //set the EnableViewState property true or dont put your code here.
}
 
Share this answer
 
Another place this can get set is on the markup in the ASPX...

<%@ Page Title="" ViewStateMode="Enabled" Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true"
 
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