Dropdownlist value is same as text after postback and in HTML (2.0

G

Guest

I'm converting this project from ASP.NET 1.1 to 2.0, and the thing I came
across is that my dropdownlist no returns the content of the Value property
in a correct way. I'm not using a direct Database connection or anything,
most of my dropdownlists are filled with values from static singletons that
are running or just some code that is generated at page_load.

The basic thing is that on page_load I always create a ListItemCollection
containing the items I want. The items have different content for Value and
Text. When using the debugger it is very clear that on creation my ListItems
are created as I want them. On PostBack however (the ListItemCollections are
not re-generated on postback) the ListItems in the dropdownlist contain the
same content for Value and Text (this is always the original content of
Text). So I am unable to locate the original Value these items had. YES, I
have EnableViewState set to true and NO it's not an option to re-generate the
collections after every postback. Why doesn't this normal feature work in
ASP.NET 2.0? I have tested it on 2 enviroments (local workstation and a
testserver), both indicate the same problem.

Under ASP.NET 1.1 this just works as it should.
 
G

Guest

Why create ListItems?

If you use

ddlObject.DataSource = dataobject;
ddlObject.DataTextField = "Field_Name_To_Show_Text";
ddlObject.DataValueField= "Field_Name_To_Store_In_Value";
ddlObject.DataBind();

I'm sure that works perfectly in both 1.1 and 2.0.

HTH

Elton Wang
 

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,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top