Find Control Inside ListView Control

前端 未结 5 1172
有刺的猬
有刺的猬 2020-12-19 08:06

I want to find \"Label\" control with ID = \"Label\" inside the \"ListView\" control. I was trying to do this with the following code:

((Label)this.ChatListV         


        
5条回答
  •  猫巷女王i
    2020-12-19 08:48

    One simple solution to this problem, which avoids the FindControl code is to place OnInit on your label.

    This would change your page code to this:

    And in your code behind you will now have a function like this:

    protected void Label_Init(object sender, EventArgs e)
    {
         Label lblMyLabel = (Label)sender;
         lblMyLabel.Text = "My Text";
    }
    

提交回复
热议问题