Ask a Question related to ASP.NET General, Design and Development.
-
anastasia #1
DataBound ListBox
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 the
user 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 the
newsgroup 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 does
not help me.
I do have ViewState for the control set to True. I tried hardcoding
the 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
anastasia Guest
-
listbox to populate a listbox
I am trying to use a listbox that I have setup using flash remoting call to a db. What I want to happen is when you click on a item in first the... -
click listbox and refresh another listbox
Can someone guide me to a resource on building set of drill-down listboxes? Basically I want to have 4 listboxes. The first starts out with... -
Item label displays as "," when moving from listbox to listbox
I have 2 listboxes: "lb_unselected" and "lb_selected". The first thing in the actions is loop through an array populating these two listboxes. ... -
now desparate! - 1st listbox contents disappears when 2nd listbox appears?
On 23 Jun 2003 12:57:45 -0700, KathyBurke40@attbi.com (KathyB) wrote: Its been a while since you posted but I will answer anyway. The problem... -
xml & databound (sorting & top 5)
Hi, I have two small questions concerning databounding an xml file to a datalist. 1. Can i do (ascending/descending) sorting on a certain... -
David Waz... #2
DataBound ListBox
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...
when the>-----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,the server>user selects one of the items and the page is posted toSelectedIndex i>,the SelectedItem property of the List is null and thepeople on the>(-1). I am tearing my hair out because I have foundin the>newsgroup with a similar
>problem, but it was due to their not setting data sourceit still does>"this.PostBack =False" condition. I have done that, andhardcoding>not help me.
>
>I do have ViewState for the control set to True. I triedread correctly.>the ListItems in the HTML and the control values were>
>I am sure I am missing the obvious here..but please help!!
>
>Thanks,
>Stacey
>.
>David Waz... Guest
-
Jim Blizzard [MSFT] #3
RE: DataBound ListBox
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..." <dlw@pickpro.com>
>Sender: "David Waz..." <dlw@pickpro.com>
>References: <fdf3218d.0307021116.34878f84@posting.google.com >
>Subject: DataBound ListBox
>Date: Wed, 2 Jul 2003 20:20:59 -0700
>Lines: 57
>Message-ID: <057501c34112$1f8d8150$a501280a@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...
>>when the>>-----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,>the server>>user selects one of the items and the page is posted to>SelectedIndex i>>,the SelectedItem property of the List is null and the>people on the>>(-1). I am tearing my hair out because I have found>in the>>newsgroup with a similar
>>problem, but it was due to their not setting data source>it still does>>"this.PostBack =False" condition. I have done that, and>hardcoding>>not help me.
>>
>>I do have ViewState for the control set to True. I tried>read correctly.>>the ListItems in the HTML and the control values were>>>
>>I am sure I am missing the obvious here..but please help!!
>>
>>Thanks,
>>Stacey
>>.
>>Jim Blizzard [MSFT] Guest
-
Gerrod Thomas #4
Re: DataBound ListBox
Hi Stacey,
I was having this exact same problem, and it was almost hair-tearing
time for me. My issue turned out to be that I had the drop down list in
a panel, and I had turned ViewState off for that panel. Hence the drop
down list wasn't putting it's stuff into the ViewState, so when the page
loaded back up the list was empty.
So make sure you check -
* That ViewState is enabled for the drop down list
* ViewState is enabled for all parent containers (ie. panels,
placeholders, etc)
* ViewState is enabled for the page
Hope that helps -
gerrod
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Gerrod Thomas Guest
-
gerrod #5
Re: DataBound ListBox
Stacey -
No, I'm not binding on post-back either - I am binding on page load
only. But the problem was that since the data was not being put into the
ViewState (since it was disabled by the holding panel), on post back the
drop down list was empty.
gerrod
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
gerrod Guest
-
anastasia #6
Re: DataBound ListBox
hi gerrod:
i was replying to David Waz....
in any case, I tried your suggestion and you were right! Thank you. I
did not have view state set for the document. Don't know how that
happened....
Thanks again!
stacey
anastasia Guest



Reply With Quote

