Stacey is not binding on the postback--at least not in the code below.
Notice the ! (not) in the IF statement. The code shown says to do the
binding if it's not a postback.
We need to see more of the code. What else happens if it IS a postback?
Do you manually re-populate the dropdownlist if it is a postback. If
that's the case, then that's the problem.
-bliz
--
Jim Blizzard
Sr .NET Developer Evangelist
Microsoft
Your Potential. Our Passion.
This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only, so that others may benefit. Thanks.
--------------------
Content-Class: urn:content-classes:message
From: "David Waz..." <dl*@pickpro.com>
Sender: "David Waz..." <dl*@pickpro.com>
References: <fd**************************@posting.google.com >
Subject: DataBound ListBox
Date: Wed, 2 Jul 2003 20:20:59 -0700
Lines: 57
Message-ID: <05****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNBEh+LwSBUfYKPT5OjrwgxMvdL4g==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa09.phx.gbl
Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.aspnet:31926
NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
You don't want to bind the data on post-back.
You are wiping out the results when you bind the data!
only bind when postback is TRUE, or when you know the
content will/should be changing. Otherwise, the viewstate
will handle everything else for you automatically.
email if you need more...
-----Original Message-----
I have the following code (this is a snippet):
InitDBConn();
OpenDBConnection();
OleDbCommand cmdRidge = new OleDbCommand("SELECT * FROM
TRDRidgeTypes", oleDbConn);
OleDbDataReader oleRidges= cmdRidge.ExecuteReader();
if (!this.IsPostBack)
{
ddlRidge.DataSource = oleRidges;
ddlRidge.DataMember = "TRDRidgeTypes";
ddlRidge.DataTextField = "RidgeType";
ddlRidge.DataValueField = "RidgeTypeID";
ddlRidge.DataBind();
}
----
This code successfully fills a DropDownList box. However,
when theuser selects one of the items and the page is posted to
the server,the SelectedItem property of the List is null and the
SelectedIndex i(-1). I am tearing my hair out because I have found
people on thenewsgroup with a similar
problem, but it was due to their not setting data source
in the"this.PostBack =False" condition. I have done that, and
it still doesnot help me.
I do have ViewState for the control set to True. I tried
hardcodingthe ListItems in the HTML and the control values were
read correctly.
I am sure I am missing the obvious here..but please help!!
Thanks,
Stacey
.