Access to DropDownList in a DataGrid from Page_Load

G

Guest

Hi folks,

Page_Load has the following definition:
Sub Page_Load(sender as Object, e as EventArgs)

As such, we are unable to instantiate a control that is inside a DataGrid
since
the e parameter is an EventArgs and not a DataGridCommandEventArgs type.

If I have a ddl and I want to load items automatically as the page loads,
how can I access the control from Page_Load.

If the ddl was not in a DataGrid, I could simply write:
Dim ddl as DropDownList = e.Item.Cells(1).FindControl("ddl")

but this does not work when the ddl is inside a DataGrid.

Thanks for any replies,
glenn
 
G

Guest

If the DataGrid is on the page then you can just use
Dim ddl as DropDownList = MyDataGridID.FindControl("ddlD")

ddl should now be a reference to the ddl within the datagrid. If the dll
was not in a datagrid you could just reference it by it's ID within the page
load and all other event handlers.
 
J

Jeff Dillon

Add a UNION statement to your SQL, then you don't have to bother with this.
You can combine "auto" load items and databound items in your ddl. We do it
here all the time. Save yourself a LOT of time.
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,811
Latest member
SaulFernan

Latest Threads

Top