0

I have a nested DataList in MasterPage. I'm trying to Findcontrol, but it returns null for DataList2.

What I tried so far :

DataList DataList1 = Page.Master.FindControl("DataListMain") as DataList;

DataList DataList2 = DataList1.FindControl("DataListNested") as DataList;

How can I fix this?

VDWWD
  • 35,079
  • 22
  • 62
  • 79
Bengi Besçeli
  • 3,638
  • 12
  • 53
  • 87

1 Answers1

0

DataList has items. So you need to locate the nested DataList by index.

DataList dl = ((DataList)Master.FindControl("DataListMain")).Items[i].FindControl("DataListNested") as DataList;

Note however that the contents of the Master Page are loaded AFTER the contents of the page using that master.

VDWWD
  • 35,079
  • 22
  • 62
  • 79