Reference to a ListBox inside a DataList

C

Clodoaldo

I'm trying to get a reference to a ListBox inside a DataList without
success. It always returns null.

I need to have a reference to the ListBox in Load time in order to
bind it to data.

This is the best I can do:

ListBox listBox = (ListBox)
(((DataList)this.Page.FindControl("DataList_1")).FindControl(listBoxID));

Any ideas?
 
S

S. Justin Gengo

Clodoaldo,

You mention trying to find the list box in "load time". In case you aren't
make sure you are attemting the find control inside of the datalist's
itemdatabound event. Until the datalist's databind event fires the list box
won't exist yet. Then you can use the event args to find your control.

Here's a link to some example code from microsoft:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx

--
Sincerely,

S. Justin Gengo, MCP

Free code and component libraries at:
http://www.aboutfortunate.com
 

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,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top