Access a control inside a the LayoutTemplate of a ListView

后端 未结 5 820
花落未央
花落未央 2020-12-17 09:05

How do I access a Control in the LayoutTemplate of a ListView control?

I need to get to litControlTitle and set its Text

5条回答
  •  隐瞒了意图╮
    2020-12-17 09:28

    This technique works for template layout; use the init event of the control:

    
      
        
        
      
      
      
    
    

    And capture a reference to the control for use in the code-behind (e.g) in the ListView's DataBound event:

    private Literal litControlTitle;
    
    protected void litControlTitle_Init(object sender, EventArgs e)
    {
        litControlTitle = (Literal) sender;
    }
    
    protected void lv_DataBound(object sender, EventArgs e)
    {
        litControlTitle.Text = "Title...";
    }
    

提交回复
热议问题