How to find controls in a repeater header or footer

前端 未结 8 2127
离开以前
离开以前 2020-11-28 02:19

I was wondering how one would find the controls in the HeaderTemplate or FooterTemplate of an Asp.Net Repeater control.

I can access them on the ItemDataBound event,

8条回答
  •  感情败类
    2020-11-28 03:01

    private T GetHeaderControl(Repeater rp, string id) where T : Control
    {
        T returnValue = null;
        if (rp != null && !String.IsNullOrWhiteSpace(id))
        {
            returnValue = rp.Controls.Cast().Where(i => i.ItemType == ListItemType.Header).Select(h => h.FindControl(id) as T).Where(c => c != null).FirstOrDefault();
        }
        return returnValue;
    }
    

    Finds and casts the control. (Based on Piyey's VB answer)

提交回复
热议问题