
Signature
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Hi Jomathan,
Ad 1. Yes, it does know.
BaseDataBoundControl:
protected internal override void OnPreRender(EventArgs e)
{
this._preRendered = true;
this.EnsureDataBound();
base.OnPreRender(e);
}
protected virtual void EnsureDataBound()
{
try
{
this._throwOnDataPropertyChange = true;
if (this.RequiresDataBinding && ((this.DataSourceID.Length > 0) ||
this._requiresBindToNull))
{
this.DataBind();
this._requiresBindToNull = false;
}
}
finally
{
this._throwOnDataPropertyChange = false;
}
}
protected virtual void OnDataPropertyChanged()
{
if (this._throwOnDataPropertyChange)
{
throw new
HttpException(SR.GetString("DataBoundControl_InvalidDataPropertyChange", new
object[] { this.ID }));
}
if (this._inited)
{
this.RequiresDataBinding = 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.SelectedIndex;
if (selectedIndex >= 0)
{
return this.Items[selectedIndex].Value;
}
return string.Empty;
}
set
{
if (this.Items.Count != 0)
{
if ((value == null) || (base.DesignMode && (value.Length == 0)))
{
this.ClearSelection();
return;
}
ListItem item = this.Items.FindByValue(value);
if ((((this.Page != null) && this.Page.IsPostBack) &&
this._stateLoaded) && (item == null))
{
throw new ArgumentOutOfRangeException("value",
SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID,
"SelectedValue" }));
}
if (item != null)
{
this.ClearSelection();
item.Selected = true;
}
}
this.cachedSelectedValue = value;
}
}
HTH

Signature
Milosz
> Thanks, but as I described, my page's Load event cannot set the selected
> value because the control has not yet been databound.
[quoted text clipped - 45 lines]
> >>
> >> Thanks!
Jonathan Wood - 10 May 2008 17:35 GMT
Milosz,
> As you can see data is bound only once (for the same datasource
> parameters).
Thanks, that's what I was wondering about. I'm not sure if I understood how,
but I've printed out your reply and will examine the code more closely.
May I ask where you got that listing? I was thinking the framework source
was unavailable. What's the trick?
> 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:
Okay, I may need the data to correctly determine which item should be
selected. But that's helpful to know the SelectedValue can be set first.
Thanks again.

Signature
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Milosz Skalecki [MCAD] - 10 May 2008 23:47 GMT
Hi Jonathan,
I used Reflector, very powerful freeware reverse engineering tool.
http://www.aisto.com/roeder/dotnet/
It will help you to understand what happens under the hood.
Have a nice weekend.

Signature
Milosz
> Milosz,
>
[quoted text clipped - 16 lines]
>
> Thanks again.
Jonathan Wood - 11 May 2008 00:22 GMT
Cool. Thanks.

Signature
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
> Hi Jonathan,
>
[quoted text clipped - 25 lines]
>>
>> Thanks again.