Cannot assign property of a WebControl

  • Thread starter Thread starter Frédéric Mayot
  • Start date Start date
F

Frédéric Mayot

Hi,

I have a strange behavior with a webcontrol. It seems that under some
conditions, it's not possible to assign a value to a property.
theControl is a ListBox

theControl.DataSource = someTable
theControl.SelectedValue = "1" ' this value belongs to someTable
theControl.DataBind()

The property SelectedValue does not change. Can you see why ?

Thanks.
Fred
 
Frédéric Mayot said:
Hi,

I have a strange behavior with a webcontrol. It seems that under some
conditions, it's not possible to assign a value to a property.
theControl is a ListBox

theControl.DataSource = someTable
theControl.SelectedValue = "1" ' this value belongs to someTable
theControl.DataBind()

The property SelectedValue does not change. Can you see why ?

SelectedValue selects the item with the given value. Before you do the
DataBind, the list control has no items to select. Try doing the DataBind
first.
 
In ASP.NET applications, until you do not call the DataBind method in a web control the items are not created (even if you have set the DataSource propoerty). Once you call this method you can reference any item since they have already been created.

Alan Ferrandiz
MCDBA, MCT, MSF Practitioner
 
Back
Top