accessing controls in datalist headertemplate from codebehind

前端 未结 2 1991
清歌不尽
清歌不尽 2021-01-26 15:28

I have a datalist in my application whose headertemplate has a lable.Now i need to access the lable from codebehind.How can i do that..

CODE:

         


        
2条回答
  •  孤街浪徒
    2021-01-26 15:41

    Attach OnItemDataBound event with your datalist like this

    
    ...
    

    And define it like this

    protected void Dlitems_ItemDataBound(Object sender, DataListItemEventArgs e)
    {
       if (e.Item.ItemType == ListItemType.Header)
       {
           Label lblCat = (Label)e.Item.FindControl("lblcat");
           lblCat.Text = "Changed!";
    
        }    
    }
    

提交回复
热议问题