Can't find control within asp.net repeater?

前端 未结 5 1094
广开言路
广开言路 2020-12-08 20:19

I have the following repeater below and I am trying to find lblA in code behind and it fails. Below the markup are the attempts I have made:



        
5条回答
  •  借酒劲吻你
    2020-12-08 20:56

    I just had the same problem.

    We are missing the item type while looping in the items. The very first item in the repeater is the header, and header does not have the asp elements we are looking for.

    Try this:

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {Label lblA = (Label)rptDetails.Items[0].FindControl("lblA");}
    

提交回复
热议问题