Cannot assign property of a WebControl

  • Thread starter Frédéric Mayot
  • 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
 
J

John Saunders

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.
 
A

Alan Ferrandiz [MCT]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top