Hi Jomathan,
Ad 1. Yes, it does know.
BaseDataBoundCo ntrol:
protected internal override void OnPreRender(Eve ntArgs e)
{
this._preRender ed = true;
this.EnsureData Bound();
base.OnPreRende r(e);
}
protected virtual void EnsureDataBound ()
{
try
{
this._throwOnDa taPropertyChang e = true;
if (this.RequiresD ataBinding && ((this.DataSour ceID.Length 0) ||
this._requiresB indToNull))
{
this.DataBind() ;
this._requiresB indToNull = false;
}
}
finally
{
this._throwOnDa taPropertyChang e = false;
}
}
protected virtual void OnDataPropertyC hanged()
{
if (this._throwOnD ataPropertyChan ge)
{
throw new
HttpException(S R.GetString("Da taBoundControl_ InvalidDataProp ertyChange", new
object[] { this.ID }));
}
if (this._inited)
{
this.RequiresDa taBinding = true;
}
}
As you can see data is bound only once (for the same datasource parameters).
Ad 2.
You can always set SelectedValue in the Page_load, even before the data has
been bound, as the SelectedValue is stored in the temporary variable until
the next databinding:
ListControl (base class for lis type control, i.e. dropdownlist, bulletedlist)
public virtual string SelectedValue
{
get
{
int selectedIndex = this.SelectedIn dex;
if (selectedIndex >= 0)
{
return this.Items[selectedIndex].Value;
}
return string.Empty;
}
set
{
if (this.Items.Cou nt != 0)
{
if ((value == null) || (base.DesignMod e && (value.Length == 0)))
{
this.ClearSelec tion();
return;
}
ListItem item = this.Items.Find ByValue(value);
if ((((this.Page != null) && this.Page.IsPos tBack) &&
this._stateLoad ed) && (item == null))
{
throw new ArgumentOutOfRa ngeException("v alue",
SR.GetString("L istControl_Sele ctionOutOfRange ", new object[] { this.ID,
"SelectedVa lue" }));
}
if (item != null)
{
this.ClearSelec tion();
item.Selected = true;
}
}
this.cachedSele ctedValue = value;
}
}
HTH
--
Milosz
"Jonathan Wood" wrote:
Thanks, but as I described, my page's Load event cannot set the selected
value because the control has not yet been databound.
My question relates to calling the control's DataBind() method. If I do
that, then the control has data. But my concern is about performance if the
control automatically performs DataBind() before the page is finished, which
would mean it happens twice.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Manish" <Ma****@discuss ions.microsoft. comwrote in message
news:75******** *************** ***********@mic rosoft.com...
Hi Jonathan,
Please know that if you bind the dropdownlist control at design time with
some datasource then also specify also specify its text and value fields
to
one of the column of the table. then you do not need to bind the
dropdownlist
at run time.
Also, you can set the Selected Value of the control by calling
Me.DropDownList 1.SelectedValue = 76
but for that dropdownlist control should be bound.
Regards,
Manish
www.componentone.com
"Jonathan Wood" wrote:
I have a databound dropdownlist control. Based on some other criteria, I
need to specify the selected item in my pages Load event.
The problem is that, in my load event, the control does not yet have any
data. I've found I can call DataBind() on that control and then it works
okay. However, this has me wondering where the control normally
databinds,
and if me doing it manually would actually introduce the overhead of
having
the control databind twice.
Can anyone answer these questions?
1. Does a control know it's been databound such that it will not repeat
the
process unecessarily?
2. Is there a better way to specify the selected value of a control that
has
not yet databound?
Thanks!
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com