Click here to Skip to main content
15,905,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All....

I have a label in the header of a datalist....i want to set the text of that label through code-behind....but i don't know how to find that control through code....i am new to ASP.net...



Thank You
Posted

Use FindControl() Method to find the Label control

C#
protected void datalist_ItemDataBound(object sender, DataListItemEventArgs e)
{
    Label HeaderLabel=(Label) e.Item.FindControl("HeaderLabel");

        HeaderLabel.text="Your text";
}
 
Share this answer
 
v3
DataList has event OnItemCreated, overriding allows select type of row:
Label _lblLabel1;
void Item_Created(Object sender, DataListItemEventArgs e)
{

   if (e.Item.ItemType == ListItemType.Footer)
   {

      __lblLabel1 =(Panel)e.Item.FindControl("lblLabel1");
     __lblLabel1.Text="";

    }

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900