TikkTakk-Aicon
asked on
Access controls in DataList
I have a DataList control on my page and inside are some dropdownlists. When the first dropdownlist is changed I need to change other dropdowns as well. I have been trying to access these controls like this:
Dim ddl As DropDownList = DirectCast(sender, DropDownList)
Dim dataItem As DataListItem = TryCast(ddl.NamingContaine r, DataListItem)
ddlFlokkur = TryCast(dataItem.FindContr ol("DataLi st1$ctl00$ ddlFlokkur "), DropDownList)
The error I get when I try to work with ddlFlokkur is Object reference not set to an instance of an object.
How can I access dropdownlists in the datalist and work with them ?
Dim ddl As DropDownList = DirectCast(sender, DropDownList)
Dim dataItem As DataListItem = TryCast(ddl.NamingContaine
ddlFlokkur = TryCast(dataItem.FindContr
The error I get when I try to work with ddlFlokkur is Object reference not set to an instance of an object.
How can I access dropdownlists in the datalist and work with them ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So if I´m looking for a dropdownlist that is in a datalist I should call the function like this ?
ddlFlokkur = FindControlRecursive(DataL ist1, "DataList1$ctl00$ddlFlokku r")
ddlFlokkur = FindControlRecursive(DataL
Yes. Try it. This will only work if "DataList1$ctl00$ddlFlokku r" is an existing control with that name inside DataList1. Also, why are you using unique ID construct for the control (i.e. "DataList1$ctl00$ddlFlokku r")? Would the control name of this inside your template would be ddlFlokkur inside the DataList1? If this is the case, you don't need to add this DataList1$ctl00$.
ASKER
I tried this like this ddlFlokkur = FindControlRecursive(DataL ist1, "ddlFlokkur") and it seems to be working. I´m still working on this and will check this further. But so far so good.
That is good to hear. Goodluck! :-)
By the way, in my previous post, "id" in the parameter is the name of the control you are looking for and "root" is the parent control of the child control you are looking for.
I hope this helps.