Click here to Skip to main content
14,330,747 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

You should enable view state.Go to properties of the DropdownList and set enableviewstate to true.
   
Comments
narayana4057 4-Jul-11 0:33am
   
Hi thanks for ur information, the Enable View state Property is already true for the Dropdown list.
Rate this:
Please Sign up or sign in to vote.

Solution 6

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";
   
Comments
Tech Code Freak 5-Jul-11 5:27am
   
My 5!
Monjurul Habib 5-Jul-11 5:46am
   
thank you.
Rate this:
Please Sign up or sign in to vote.

Solution 2

There must be some problem in your code. I would appreciate if you share your code....

++Subhendu
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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.
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 7

Another place this can get set is on the markup in the ASPX...

<%@ Page Title="" ViewStateMode="Enabled" Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true"
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100