If your ddl is reverting to the first item and not keeping the selected
item from prior to the postback, you are probably calling databind() on
the control on the postback. Here is a general rule of thumb for
getting data, binding to it and the Page_Load event:
In page load, before checking the IsPostBack property, get your data.
Then check if the page is being posted back. If not, call DataBind on
the controls.
Page_Load(<<args>>)
{
// get data.
dataAdapter.Fill(dataTable);
// check for postback.
if (!this.IsPostBack)
{
control.DataBind();
}
}
The exception to this would be if you are using a datareader for your
ddl. Then get the datareader and bind the control only if the page is
NOT a postback.
Page_Load(<<args>>)
{
// check for postback.
if (!this.IsPostBack)
{
// get data reader.
SqlDataReader dr = someCommand.ExecuteReader();
control.DataSource = dr;
control.DataTextField = "SomeTextField";
control.DataValueField = "SomeValueField";
control.DataBind();
}
}
John
-----Original Message-----
From: darrel [mailto:no*****@hotmail.com]
Posted At: Friday, August 26, 2005 1:02 PM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: My DropDownList handler isn't executing.
Subject: Re: My DropDownList handler isn't executing.
However, my handler doesn't seem to execute (even though there is a
postback).
Hmm...I also have another problem. The auto-postback isn't retaining the
selected value. It keeps reverting to the first item.
I don't normally use drop down auto-postbacks, so am I just completely
not 'getting' some fundamental concept here?
-Darrel