findcontrol to find in nested datalists

G

Greg Fischer

I need to access the properties of a control that is nested in 2 datalists.
How do you use findcontrol method to do that?

what I have is like this:

<asp:datalist id="dlist" runat="server">
<edititemtemplate>
<asp:datalist id="dlistdet" runat="server">
<asp:dropdownlist id="ddlTypes" runat="server"></dropdownlist>
</asp:datalist>
</edititemtemplate>
</asp:datalist>


Every thing loads fine. The ddlTypes is loaded from a database and I
can see it's results. I need to access the selected value on it
directly. I am able to access a control from within the first dlist by
using:

neededitem = CType(e.Item.FindControl("controlname"), TextBox)

But what is the syntax to drill down further into that edititemtemplate
and the dlistdet? Also, I am running this from the event
SelectedIndexChanged
on the dropdownlist, and I dont have the e.item.findcontrol. what I am
trying is something like this:

Dim ddl As DropDownList =
CType(dlist.Items(dlist.SelectedIndex).FindControl("ddlTypes"),
DropDownList)

But that isnt working. Not sure what it's supposed to look like.

Thank you for the assistance!

Greg Fischer
1st Byte Solutions
http://www.1stbyte.com
 
S

Scott Allen

Hi Greg:

You are using this from the SelectedIndexChanged event? If so, the
sender parameter is the DropDownList control, you'll just need to
CType it into a DropDownList and then start party.
 
G

Greg Fischer

Ah, yes! That's right. thanks!

this was it...

Public Sub cmbAddType_OnSelect(ByVal s As System.Object, ByVal e As
System.EventArgs) Handles cmbAddType.SelectedIndexChanged

Dim ddl As DropDownList = CType(s, DropDownList)

From there I have all the properties!

Cool!
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top